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
Python
NodeJS
REST
OpenAI Python
OpenAI NodeJS
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)
import Portkey from 'portkey-ai';
import fs from 'fs';
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
provider: "@anthropic"
});
const file = await portkey.files.create({
purpose: "assistants",
file: fs.createReadStream("document.pdf")
});
console.log(file.id);
curl -X POST https://api.portkey.ai/v1/files \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "x-portkey-provider: @anthropic" \
-H "anthropic-beta: files-api-2025-04-14" \
-F 'file=@"document.pdf"'
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
client = OpenAI(
api_key="PORTKEY_API_KEY",
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="@anthropic",
api_key="PORTKEY_API_KEY"
)
)
file = client.files.create(
purpose="assistants",
file=open("document.pdf", "rb")
)
print(file.id)
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
import fs from 'fs';
const client = new OpenAI({
apiKey: "PORTKEY_API_KEY",
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
provider: "@anthropic",
apiKey: "PORTKEY_API_KEY"
})
});
const file = await client.files.create({
purpose: "assistants",
file: fs.createReadStream("document.pdf")
});
console.log(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)
import Portkey from 'portkey-ai';
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY"
});
const response = await 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" } }
]
}]
});
console.log(response.choices[0].message.content);
curl -X POST https://api.portkey.ai/v1/chat/completions \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "anthropic-beta: files-api-2025-04-14" \
-H "Content-Type: application/json" \
-d '{
"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"
}
}
]
}
]
}'
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
Python
NodeJS
REST
OpenAI Python
OpenAI NodeJS
from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY",
provider="@anthropic"
)
files = portkey.files.list()
print(files)
import Portkey from 'portkey-ai';
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
provider: "@anthropic"
});
const files = await portkey.files.list();
console.log(files);
curl https://api.portkey.ai/v1/files \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "x-portkey-provider: @anthropic" \
-H "anthropic-beta: files-api-2025-04-14"
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
client = OpenAI(
api_key="PORTKEY_API_KEY",
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="@anthropic",
api_key="PORTKEY_API_KEY"
)
)
files = client.files.list()
print(files)
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
const client = new OpenAI({
apiKey: "PORTKEY_API_KEY",
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
provider: "@anthropic",
apiKey: "PORTKEY_API_KEY"
})
});
const files = await client.files.list();
console.log(files);
Get file
Python
NodeJS
REST
OpenAI Python
OpenAI NodeJS
from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY",
provider="@anthropic"
)
file = portkey.files.retrieve(file_id="<file_id>")
print(file)
import Portkey from 'portkey-ai';
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
provider: "@anthropic"
});
const file = await portkey.files.retrieve("<file_id>");
console.log(file);
curl https://api.portkey.ai/v1/files/<file_id> \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "x-portkey-provider: @anthropic" \
-H "anthropic-beta: files-api-2025-04-14"
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
client = OpenAI(
api_key="PORTKEY_API_KEY",
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="@anthropic",
api_key="PORTKEY_API_KEY"
)
)
file = client.files.retrieve("<file_id>")
print(file)
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
const client = new OpenAI({
apiKey: "PORTKEY_API_KEY",
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
provider: "@anthropic",
apiKey: "PORTKEY_API_KEY"
})
});
const file = await client.files.retrieve("<file_id>");
console.log(file);
Delete file
Python
NodeJS
REST
OpenAI Python
OpenAI NodeJS
from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY",
provider="@anthropic"
)
response = portkey.files.delete(file_id="<file_id>")
print(response)
import Portkey from 'portkey-ai';
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
provider: "@anthropic"
});
const response = await portkey.files.delete("<file_id>");
console.log(response);
curl -X DELETE https://api.portkey.ai/v1/files/<file_id> \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "x-portkey-provider: @anthropic" \
-H "anthropic-beta: files-api-2025-04-14"
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
client = OpenAI(
api_key="PORTKEY_API_KEY",
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="@anthropic",
api_key="PORTKEY_API_KEY"
)
)
response = client.files.delete("<file_id>")
print(response)
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
const client = new OpenAI({
apiKey: "PORTKEY_API_KEY",
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
provider: "@anthropic",
apiKey: "PORTKEY_API_KEY"
})
});
const response = await client.files.delete("<file_id>");
console.log(response);
Supported file types
Anthropic’s Files API supports the following file types:
| Type | MIME types |
|---|
| PDF | application/pdf |
| Images | image/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