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 — Gateway handles the provider-specific format translation.

Send a document (base64)

1import base64
2
3with open("report.pdf", "rb") as f:
4 pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")
5
6response = client.responses.create(
7 model="anthropic/claude-sonnet-4-20250514",
8 input=[
9 {
10 "type": "message",
11 "role": "user",
12 "content": [
13 {"type": "text", "text": "Summarize this document."},
14 {
15 "type": "document",
16 "source_type": "base64",
17 "media_type": "application/pdf",
18 "data": pdf_data,
19 },
20 ],
21 }
22 ],
23)
24
25print(response.output[0].content[0].text)

Send a document (URL)

URL
1response = client.responses.create(
2 model="google/gemini-2.0-flash",
3 input=[
4 {
5 "type": "message",
6 "role": "user",
7 "content": [
8 {"type": "text", "text": "What are the key findings?"},
9 {
10 "type": "document",
11 "source_type": "url",
12 "media_type": "application/pdf",
13 "data": "https://example.com/report.pdf",
14 },
15 ],
16 }
17 ],
18)

Supported models

Document input is supported by models with "document" in their capabilities.input array. Check model capabilities via GET /v1/models.

ProviderModels
AnthropicClaude Sonnet 4, Claude Haiku 3.5
GoogleGemini 2.0 Flash, Gemini 2.5 Pro

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.