Documents

Send PDFs and documents to document-understanding models

Gateway supports sending PDF documents to models with document input capability. Pass documents as base64-encoded data or a URL, and Gateway handles the provider-specific format translation.

Send a document (base64)

import base64
with open("report.pdf", "rb") as f:
pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")
response = client.responses.create(
model="anthropic/claude-sonnet-5",
input=[
{
"type": "message",
"role": "user",
"content": [
{"type": "text", "text": "Summarize this document."},
{
"type": "document",
"source_type": "base64",
"media_type": "application/pdf",
"data": pdf_data,
},
],
}
],
)
print(response.output[0].content[0].text)

AI SDK file parts require merge-gateway-ai-sdk-provider 0.3.0 or later. Earlier versions dropped every file part — documents and images alike — without an error. data may be bytes, a base64 string, a data: URI, or a URL.

Send a document (URL)

URL
response = client.responses.create(
model="google/gemini-3.6-flash",
input=[
{
"type": "message",
"role": "user",
"content": [
{"type": "text", "text": "What are the key findings?"},
{
"type": "document",
"source_type": "url",
"media_type": "application/pdf",
"data": "https://example.com/report.pdf",
},
],
}
],
)

Supported models

Document input is supported by models with "document" in their capabilities.input array. Check model capabilities via GET /v1/models, or filter by input type in the model catalog.

Documents are estimated at ~1,500 tokens per page for compression calculations. A 10-page PDF counts as roughly 15,000 tokens toward the context window.