Skip to main content
Portkey supports Anthropicโ€™s Files API (beta), enabling you to upload, list, retrieve, and delete files through the gateway. Uploaded files can be referenced in chat completions using file_id instead of re-uploading content each request.
The Files API is in beta and requires the files-api-2025-04-14 beta header. Portkey sets this automatically for file endpoints when using the SDK. For cURL requests, include the anthropic-beta: files-api-2025-04-14 header.

Upload a file

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@anthropic"
)

file = portkey.files.create(
    purpose="assistants",
    file=open("document.pdf", "rb")
)

print(file.id)

Use uploaded files in chat completions

Once a file is uploaded, reference it by file_id in your chat completions requests:
from portkey_ai import Portkey

portkey = Portkey(api_key="PORTKEY_API_KEY")

response = portkey.chat.completions.create(
    model="@anthropic/claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "Please summarize this document."},
            {"type": "file", "file": {"file_id": "<file_id>", "mime_type": "application/pdf"}}
        ]
    }]
)

print(response.choices[0].message.content)
When using the SDK, the anthropic-beta header is set automatically for file endpoints. For chat completions with file references via cURL, include anthropic-beta: files-api-2025-04-14 in your request headers.

List files

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@anthropic"
)

files = portkey.files.list()

print(files)

Get file

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@anthropic"
)

file = portkey.files.retrieve(file_id="<file_id>")

print(file)

Delete file

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@anthropic"
)

response = portkey.files.delete(file_id="<file_id>")

print(response)

Supported file types

Anthropicโ€™s Files API supports the following file types:
TypeMIME types
PDFapplication/pdf
Imagesimage/jpeg, image/png, image/gif, image/webp

Limitations

  • The Files API is only available on direct Anthropic API โ€” it is not supported on Bedrock or Vertex AI
  • Files API is currently in beta and requires the files-api-2025-04-14 beta header for cURL requests
  • Refer to Anthropicโ€™s documentation for the latest file size and rate limits
Last modified on June 25, 2026