Document & File Input
Send PDFs, text files, CSVs, and other documents to any model via a unified API.
Document & File Input
osmAPI enables your applications to send documents and files to AI models through a unified interface. Whether you're processing PDFs, analyzing CSV data, or parsing HTML pages, our gateway handles format conversion and provider-specific transformations automatically.
Supported Content Formats
Two content block formats are supported for sending documents:
1. Document Format (Anthropic-style)
Use the document content type with a base64-encoded source or a URL reference.
curl -X POST "https://api.osmapi.com/v1/chat/completions" \
-H "Authorization: Bearer $OSM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Summarize this document."
},
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "JVBERi0xLjQKJcfs..."
},
"filename": "report.pdf"
}
]
}
]
}'URL Source
You can also reference documents via URL:
{
"type": "document",
"source": {
"type": "url",
"url": "https://example.com/report.pdf"
},
"filename": "report.pdf"
}2. File Format (OpenRouter-style)
Use the file content type with a data URI or URL in file_data.
curl -X POST "https://api.osmapi.com/v1/chat/completions" \
-H "Authorization: Bearer $OSM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What does this CSV data show?"
},
{
"type": "file",
"file": {
"filename": "sales.csv",
"file_data": "data:text/csv;base64,bmFtZSxhZ2Usc2FsZXMKSm9obiwzMCwxMDAw..."
}
}
]
}
]
}'Provider Handling
osmAPI automatically routes and transforms document content based on the target provider:
| Provider | Handling | Supported Types |
|---|---|---|
| Anthropic | Native document blocks | PDF, TXT, CSV, HTML, MD |
| OpenAI | Native file support | PDF, TXT, CSV, and more |
| Google (Gemini) | Native inline_data / file_data | PDF, TXT, CSV, HTML |
| AWS Bedrock | Native Converse API document blocks | PDF, TXT, CSV, HTML |
| All other providers | Auto-conversion (see below) | Text-based formats only |
Automatic Text Conversion
For providers that don't natively support document input (e.g., Groq, Cerebras, Together, DeepSeek, Neysa), osmAPI automatically converts text-based documents to plain text content blocks. This means your request works seamlessly — no code changes needed.
Text-based MIME types (auto-converted):
| MIME Type | Extension | Auto-converted |
|---|---|---|
text/plain | .txt | Yes |
text/csv | .csv | Yes |
text/html | .html | Yes |
text/markdown | .md | Yes |
text/xml | .xml | Yes |
text/css | .css | Yes |
text/javascript | .js | Yes |
application/json | .json | Yes |
application/xml | .xml | Yes |
application/javascript | .js | Yes |
Binary formats (not auto-converted):
| MIME Type | Extension | Behavior |
|---|---|---|
application/pdf | Requires native provider support | |
application/vnd.openxmlformats... | .docx, .xlsx | Requires native provider support |
Tip: If you need to send a PDF to a model that doesn't support documents
natively, extract the text from the PDF on your side and send it as a text
content block instead.
Anthropic API Compatibility
Documents are also supported via the Anthropic-compatible endpoint (/v1/messages):
curl -X POST "https://api.osmapi.com/v1/messages" \
-H "x-api-key: $OSM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Analyze this document."
},
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "JVBERi0xLjQK..."
},
"filename": "analysis.pdf"
}
]
}
]
}'Multi-Document Requests
You can include multiple documents in a single message for comparative analysis:
{
"role": "user",
"content": [
{ "type": "text", "text": "Compare these two reports." },
{
"type": "document",
"source": { "type": "base64", "media_type": "text/csv", "data": "..." },
"filename": "q1_sales.csv"
},
{
"type": "document",
"source": { "type": "base64", "media_type": "text/csv", "data": "..." },
"filename": "q2_sales.csv"
}
]
}Model Support
Models with native document support are indicated by the documents capability flag. You can find document-capable models via the Models page.
For models without native document support, text-based documents (TXT, CSV, HTML, MD, JSON, XML) are automatically converted to text and will work with any model.
How is this guide?