API Overview
Concepts, authentication, limits, and SDK setup for the DocsRouter API
API Overview
The DocsRouter API is fully compatible with OpenAI and OpenRouter SDKs. You can use existing SDKs by simply changing the base URL. The API also provides DocsRouter-specific extensions for enhanced OCR functionality.
Base URL
All API requests should be made to the following base URL:
https://api.docsrouter.com/v1For testing and development, you can also use:
https://api.docsrouter.com/v1 (Production)Authentication
All API requests (except /v1/models and /v1/health) require authentication via the Authorization header using a Bearer token:
Authorization: Bearer YOUR_API_KEYObtaining an API Key
- Sign up at docsrouter.com
- Navigate to Dashboard → API Keys
- Click Create New Key
- Copy and securely store your key (it's only shown once)
Security Best Practices:
- Never expose API keys in client-side code or public repositories
- Use environment variables to store keys
- Rotate keys periodically
- Use separate keys for development and production
SDK Compatibility
DocsRouter works with any OpenAI-compatible SDK. Here are examples for popular languages:
Python
from openai import OpenAI
client = OpenAI(
base_url="https://api.docsrouter.com/v1",
api_key="YOUR_DOCSROUTER_API_KEY",
)
response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Extract all text from this document"},
{"type": "image_url", "image_url": {"url": "https://example.com/invoice.png"}}
]
}]
)
print(response.choices[0].message.content)JavaScript/TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.docsrouter.com/v1',
apiKey: 'YOUR_DOCSROUTER_API_KEY',
});
const response = await client.chat.completions.create({
model: 'google/gemini-2.0-flash-001',
messages: [{
role: 'user',
content: [
{ type: 'text', text: 'Extract all text from this document' },
{ type: 'image_url', image_url: { url: 'https://example.com/invoice.png' } }
]
}]
});
console.log(response.choices[0].message.content);cURL
curl -X POST https://api.docsrouter.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.0-flash-001",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Extract all text"},
{"type": "image_url", "image_url": {"url": "https://example.com/doc.png"}}
]
}]
}'Other SDKs
DocsRouter is compatible with:
- LangChain - Use the OpenAI integration with custom base URL
- LlamaIndex - Configure OpenAI LLM with DocsRouter endpoint
- Vercel AI SDK - Use OpenAI provider with custom configuration
- Any OpenAI-compatible library - Just change the base URL
Response Format
All responses follow the OpenAI standard format with DocsRouter extensions:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1734567890,
"model": "google/gemini-2.0-flash-001",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "INVOICE #001\nDate: December 15, 2024\n..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 1200,
"completion_tokens": 150,
"total_tokens": 1350
},
"docsrouter": {
"confidence": 95,
"detected_language": "en",
"pages_processed": 1,
"tables_detected": 2,
"provider": "openrouter",
"provider_cost_cents": 1.2,
"platform_fee_cents": 0.4,
"total_cost_cents": 1.6,
"processing_time_ms": 1850
}
}DocsRouter Extensions
The docsrouter object in responses contains OCR-specific metadata:
| Field | Type | Description |
|---|---|---|
confidence | number | OCR confidence score (0-100) |
detected_language | string | ISO 639-1 language code |
pages_processed | number | Number of pages/images processed |
tables_detected | number | Number of tables found |
tables | array | Extracted table data (if enabled) |
provider | string | Upstream provider used |
provider_cost_cents | number | Cost charged by provider |
platform_fee_cents | number | DocsRouter platform fee |
total_cost_cents | number | Total cost for the request |
processing_time_ms | number | Processing time in milliseconds |
Endpoints Overview
Core Endpoints
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST | /v1/chat/completions | Required | OpenAI-compatible OCR ⭐ Recommended |
POST | /v1/ocr | Required | Native OCR endpoint |
GET | /v1/models | Optional | List available models |
GET | /v1/models/{id} | Optional | Get specific model details |
Management Endpoints
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET | /v1/api-keys | Required | List API keys |
POST | /v1/api-keys | Required | Create new API key |
DELETE | /v1/api-keys/{id} | Required | Revoke API key |
GET | /v1/usage | Required | Get usage logs |
GET | /v1/usage/summary | Required | Get usage summary |
GET | /v1/account | Required | Get account details |
GET | /v1/account/balance | Required | Get account balance |
Utility Endpoints
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET | /v1/health | None | Check API status |
GET | /v1/models/stats | Optional | Get model statistics |
GET | /v1/models/recommended | Optional | Get recommended models |
Rate Limits
The API implements rate limiting to ensure fair usage and system stability:
| Tier | Requests/Minute | Requests/Day | Concurrent |
|---|---|---|---|
| Free | 10 | 100 | 2 |
| Starter | 60 | 1,000 | 5 |
| Pro | 300 | 10,000 | 20 |
| Enterprise | Custom | Custom | Custom |
Rate Limit Headers
Every response includes rate limit information:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 58
X-RateLimit-Reset: 1734567890| Header | Description |
|---|---|
X-RateLimit-Limit | Maximum requests allowed in the window |
X-RateLimit-Remaining | Requests remaining in current window |
X-RateLimit-Reset | Unix timestamp when the window resets |
Retry-After | Seconds to wait (only on 429 responses) |
Request Limits
| Limit | Value |
|---|---|
| Maximum request body size | 50 MB |
| Maximum image size | 20 MB |
| Maximum PDF size | 50 MB |
| Maximum pages per PDF | 100 |
| Maximum images per request | 10 |
| Request timeout | 120 seconds |
Supported File Formats
Images
| Format | MIME Type | Notes |
|---|---|---|
| PNG | image/png | Recommended for documents |
| JPEG | image/jpeg | Good for photos |
| WebP | image/webp | Efficient compression |
| GIF | image/gif | First frame only |
| TIFF | image/tiff | High-quality scans |
| BMP | image/bmp | Uncompressed |
Documents
| Format | MIME Type | Notes |
|---|---|---|
application/pdf | Use mistral-ocr engine for scanned PDFs |
Pricing
DocsRouter pricing is 5% above OpenRouter rates, covering our unified API, OCR extensions, and platform services.
Per-Request Costs
Costs are calculated based on:
- Input tokens - Text and image tokens sent to the model
- Output tokens - Generated text tokens
- PDF processing - Additional fee for PDF engine (if used)
- Document conversion - Additional fee for office documents (if needed)
PDF Engine Pricing
| Engine | Cost | Best For |
|---|---|---|
pdf-text | Free | Digital PDFs with selectable text |
mistral-ocr | $0.105/1,000 pages | Scanned documents, images in PDFs |
native | Model token cost | Models with native PDF support |
Document Conversion Pricing
For office documents (DOCX, PPTX, DOC, ODT, RTF, TXT) that need to be converted to images before processing with Vision LLMs:
| Document Type | Estimated Cost | Notes |
|---|---|---|
| Simple documents | ~1-2¢ | DOCX, DOC, TXT, RTF |
| Presentations | ~1-3¢ | PPTX (10-50 slides) |
| Complex documents | ~2-5¢ | Large documents with many pages |
Minimum charge: 1¢ per conversion
Tip: Mistral OCR (mistral-ocr-latest) natively supports DOCX and PPTX without conversion fees. Use it for the most cost-effective office document processing.
Cost Transparency
Every response includes detailed cost breakdown:
{
"docsrouter": {
"provider_cost_cents": 1.2,
"platform_fee_cents": 0.4,
"conversion_cost_cents": 1.0,
"total_cost_cents": 2.6
}
}Versioning
The API is versioned via the URL path (/v1/). We maintain backward compatibility within major versions.
- v1 (current) - Stable, production-ready
- Breaking changes will be announced 90 days in advance
- Deprecation notices are included in response headers
Support
- Documentation: docs.docsrouter.com
- Status Page: status.docsrouter.com
- Email: [email protected]
- Discord: Join our community