This page describes features extending the AI Gateway, which provides a unified API for accessing multiple AI providers. To learn more, see AI Gateway.
Quick Start
Send PDF documents directly in chat messages for analysis and content extraction.Configuration
| Parameter | Type | Required | Description |
|---|---|---|---|
type | "file" | Yes | Content type for file input |
file.file_data | string | Yes | Data URI with base64 PDF content |
file.filename | string | Yes | Name of the file for model context |
data:application/pdf;base64,{base64_content}
Supported Models
| Provider | Model | PDF Support |
|---|---|---|
| OpenAI | gpt-4o | ✅ Native |
| OpenAI | gpt-4o-mini | ✅ Native |
| OpenAI | gpt-4-turbo | ✅ Native |
| Anthropic | claude-3-sonnet | ✅ Via conversion |
| Anthropic | claude-3-haiku | ✅ Via conversion |
Use Cases
| Scenario | Best Model | Example Prompt |
|---|---|---|
| Contract analysis | gpt-4o | ”Extract key terms and obligations” |
| Invoice processing | gpt-4o-mini | ”Extract amounts, dates, vendor info” |
| Research papers | gpt-4o | ”Summarize methodology and findings” |
| Form extraction | gpt-4o-mini | ”Convert form data to JSON” |
Code examples
File Handling
Reading PDF files:Best Practices
File preparation:- Compress PDFs to reduce size (under 20MB recommended)
- Ensure text is selectable (not scanned images)
- Remove unnecessary pages for focused analysis
- Use clear, structured layouts for better extraction
Troubleshooting
**PDF not processing- Verify base64 encoding is correct
- Check file size (under model’s context limit)
- Ensure MIME type is
application/pdf - Try with a different model
- Use higher-quality models (gpt-4o vs gpt-4o-mini)
- Provide more specific prompts
- Break complex documents into sections
- Consider preprocessing scanned PDFs with OCR
- Compress PDFs before sending
- Extract only relevant pages
- Use streaming for large documents
- Cache results for repeated analysis
Limitations
| Limitation | Details | Workaround |
|---|---|---|
| File size | Model context limits | Split large PDFs |
| Scanned documents | Quality varies by model | Use OCR preprocessing |
| Complex layouts | Tables/charts may not extract well | Use structured prompts |
| Security | Sensitive documents sent to provider | Use on-premise models |
| Cost | Large files consume more tokens | Optimize file size |