PDF Inputs
Send PDF documents to TheRouter.ai models through chat completions
PDFs are supported through the file content type. You can send either public PDF URLs or base64-encoded data URLs. TheRouter.ai routes to native file-capable models when possible and can parse PDFs when native file handling is unavailable.
Native vs parsed flow
When the selected model supports file input natively, TheRouter.ai forwards the file directly. Otherwise, TheRouter.ai parses the PDF and sends extracted content to the model.
Configure PDF processing skills
pdf-skill-config.json
{
"skills": [
{
"id": "file-parser",
"config": {
"pdf": {
"engine": "pdf-text"
}
}
}
]
}Common engines: pdf-text, mistral-ocr, and native.
Using a PDF URL
TypeScript
const response = await fetch("https://api.therouter.ai/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer <THEROUTER_API_KEY>",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "anthropic/claude-sonnet-4.5",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Summarize the key points in this document" },
{
type: "file",
file: {
filename: "bitcoin.pdf",
file_data: "https://bitcoin.org/bitcoin.pdf",
},
},
],
},
],
}),
});Using base64 PDF input
base64-pdf.ts
import fs from "node:fs/promises";
const pdfBuffer = await fs.readFile("./report.pdf");
const dataUrl = "data:application/pdf;base64," + pdfBuffer.toString("base64");
await fetch("https://api.therouter.ai/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer <THEROUTER_API_KEY>",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "google/gemini-2.5-pro",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Extract action items from this document" },
{ type: "file", file: { filename: "report.pdf", file_data: dataUrl } },
],
},
],
}),
});Skipping repeated parse costs
Reuse returned file annotations in follow-up requests to avoid re-parsing the same document repeatedly.
file-annotation-schema.json
{
"type": "file",
"file": {
"hash": "abc123",
"name": "report.pdf",
"content": [
{ "type": "text", "text": "..." },
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,..." } }
]
}
}Cost optimization
Annotation reuse is especially useful for large PDFs or OCR-heavy workflows where parse cost dominates.