Files
The Beta Files API provides a provider-agnostic interface for uploading, listing, reading, and deleting files used by multimodal workflows. It wraps each provider's native files endpoint behind a single async client.
When to use Files API#
Use FilesAPI when you want to:
- Upload large assets once, then reference them by
file_id - Manage file lifecycle in your app (list and delete stale files)
- Keep file handling logic consistent across supported providers
Supported providers#
FilesAPI is available for:
OpenAIConfigOpenAIResponsesConfigAnthropicConfigGeminiConfig
Note
Gemini does not support downloading file bytes via its Files API. FilesAPI.read() raises NotImplementedError for Gemini.
Create a Files API client#
Upload files#
You can upload from a local path or from in-memory bytes.
Upload from local path#
Upload from bytes#
If data is provided without filename, upload() raises ValueError.
Read, list, and delete#
You can also call read() from an UploadedFile:
Use uploaded files in agent requests#
After upload, pass the returned file_id to an input event.
For more multimodal details, see Multimodal Inputs.