.env.local (not committed to version control).
Quick Setup
.env.local with your values.
Required Variables
Your OpenRouter API key for accessing vision models.How to get it:
- Sign up at openrouter.ai
- Navigate to openrouter.ai/keys
- Create a new API key
- Copy the key to your
.env.localfile
Model Configuration
Default vision model for OCR operations.Used by:
/api/ocr(raw text extraction)/api/ocr-structured(legacy structured extraction)/api/ocr-structured-v4(normalized GST extraction)
- If not set: defaults to
google/gemini-2.0-flash - Can be overridden per-request via the
modelfield in API request body
See Model Selection for guidance on choosing the right model for your use case.
PDF Processing
PDF parsing engine used by OpenRouter’s file-parser plugin.Available engines:Per-request override:
You can override this setting by passing a
pdf-text(default) - Fast text extraction, works with most PDFsmistral-ocr- OCR-based extraction for scanned PDFs or images within PDFsnative- Provider’s native PDF handling
/api/ocrwhen processing PDFs/api/ocr-structured-v4when processing PDFs
plugins array in the request body:OpenRouter Metadata
These variables are sent as headers to OpenRouter for analytics and billing purposes.Your application’s URL, sent in the
HTTP-Referer header.Example:OpenRouter uses this for analytics and to help identify your application in their dashboard.
Your application’s name, sent in the
X-Title header.Example:Complete Example
Here’s a complete.env.local file with all variables configured:
.env.local
Environment Variable Priority
For each API route, the priority order is:- Request body parameter (e.g.,
modelfield in POST body) - Environment variable (from
.env.local) - Default value (hardcoded in the route)
Example: Model Selection
- Set a default model in
.env.local - Override it per-request when needed
- Fall back to a sensible default if neither is provided
Troubleshooting
Error: Server missing OPENROUTER_API_KEY
Error: Server missing OPENROUTER_API_KEY
This means
OPENROUTER_API_KEY is not set in your .env.local file.Solution:- Create
.env.localif it doesn’t exist - Add
OPENROUTER_API_KEY=your-key-here - Restart the development server
Changes to .env.local not taking effect
Changes to .env.local not taking effect
Next.js loads environment variables at startup.Solution:
- Stop the dev server (Ctrl+C)
- Restart with
npm run dev
API key showing in logs or error messages
API key showing in logs or error messages
The application filters API keys from error messages, but be cautious.Best practices:
- Never log
process.env.OPENROUTER_API_KEY - Use server-side only (never expose to client)
- Rotate keys regularly
Next Steps
OpenRouter Setup
Step-by-step guide to getting your OpenRouter API key
Model Selection
Choose the right model for your use case
