What is OpenRouter?
OpenRouter is a unified API gateway that provides access to multiple AI models from providers like:- OpenAI (GPT-4o, GPT-4o-mini)
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus)
- Google (Gemini Pro, Gemini Flash)
- And many more
- Single API key for all models
- Pay-as-you-go pricing
- Model fallbacks and routing
- Usage analytics and monitoring
Step 1: Create an Account
Visit OpenRouter
Go to openrouter.ai
Step 2: Add Credits
OpenRouter uses a prepaid credit system.Navigate to Credits
After signing in, go to openrouter.ai/credits
Pricing for Invoice OCR:
- Most invoices cost 0.01 to process
- A $5 credit can process 500-5000 invoices depending on model choice
- See Model Selection for cost comparisons
Step 3: Generate API Key
Go to Keys Page
Navigate to openrouter.ai/keys
Create New Key
Click “Create Key” and provide:
- Name: e.g., “Invoice OCR Development”
- Credit limit (optional): Set a spending limit for this key
- Allowed origins (optional): Restrict to specific domains
Copy the Key
Your API key will be displayed only once. Copy it immediately.Format:
sk-or-v1-... (64 characters)Step 4: Verify Setup
Test your configuration:Open the Application
Navigate to http://localhost:3000
Upload a Test Invoice
- Click “Upload Invoice” or drag-and-drop an image
- Select an OCR mode (try “Normalized GST v4”)
- Click “Extract”
API Key Management
Multiple Keys
Create separate API keys for different environments:.env.local (development)
.env.production (production)
Key Limits
Set spending limits per key:- Go to openrouter.ai/keys
- Click on a key to edit
- Set “Credit Limit” (e.g., $10/month)
- Save changes
This prevents unexpected charges if your application has high usage or is compromised.
Rotating Keys
Rotate keys periodically for security:Create New Key
Generate a new key at openrouter.ai/keys
Monitoring Usage
Track your API usage and costs:Usage Dashboard
- Go to openrouter.ai/activity
- View:
- Request count by model
- Total cost per day/week/month
- Average cost per request
- Error rates
Per-Key Analytics
View usage for a specific key:- Go to openrouter.ai/keys
- Click on a key name
- View detailed usage stats
Troubleshooting
Invalid API key error
Invalid API key error
Possible causes:
- Key copied incorrectly (check for extra spaces)
- Key was deleted from OpenRouter dashboard
- Key expired or reached credit limit
- Verify key in
.env.localmatches dashboard - Generate new key if needed
- Check credit balance
Insufficient credits
Insufficient credits
Error message: “Insufficient credits” or 402 status codeSolution:
- Go to openrouter.ai/credits
- Add more credits
- Retry the request
Rate limit exceeded
Rate limit exceeded
Error message: “Rate limit exceeded” or 429 status codeSolution:
- Wait a few seconds and retry
- Implement exponential backoff in your code
- Upgrade to a higher tier plan if needed
Model not available
Model not available
Error message: “Model not found” or “Model not available”Solution:
- Check available models at openrouter.ai/models
- Some models require allowlist access
- Update
OPENROUTER_MODELto a supported model
OpenRouter Headers
Invoice OCR sends the following headers to OpenRouter:HTTP-Referer: Identifies your application in OpenRouter analyticsX-Title: Displays a friendly name in your usage dashboard
.env.local:
Next Steps
Environment Variables
Complete reference for all configuration options
Model Selection
Choose the best model for your use case
Quick Start
Start extracting invoice data
API Reference
Integrate OCR into your application
