Navigation
OpenRouter SetupOpenRouter Setup
OpenRouter configuration, model selection, API keys, and usage in Scriptonia.OpenRouter Configuration
Scriptonia uses OpenRouter as an OpenAI-compatible API to run Idea, Intent, Platform, and Execution (all agents). The client is inlib/openai.ts: it uses fetch to OPENROUTER_BASE_URL (default https://openrouter.ai/api/v1/chat/completions), not the OpenAI SDK.
Base URL
Required: at least one model key
You must set at least one of:- OPENROUTER_API_KEY_GROK4
- OPENROUTER_API_KEY_QWEN3
- OPENROUTER_API_KEY_GEMINI2_5
- GROK_API_KEY
- QWEN_API_KEY
- GEMINI_API_KEY
lib/openai.ts uses OPENROUTER_API_KEY_* first, then the legacy key for that model.If the chosen model’s key is missing, the LLM call throws.
Model Selection
Configured models
| Key | Model ID (env override) | Env for API key |
|---|---|---|
| GROK | GROK4_MODEL default x-ai/grok-4-fast | OPENROUTER_API_KEY_GROK4 or GROK_API_KEY |
| QWEN | QWEN3_MODEL default qwen/qwen3-235b-a22b-2507 | OPENROUTER_API_KEY_QWEN3 or QWEN_API_KEY |
| GEMINI | GEMINI2_5_MODEL default google/gemini-2.5-flash | OPENROUTER_API_KEY_GEMINI2_5 or GEMINI_API_KEY |
Default model
Overriding model IDs
API Key Setup
1. OpenRouter account
- Sign up at OpenRouter
- Add a key in the dashboard
- One key can access multiple models if your plan allows
2. Env vars
In.env (or .env.local), set at least the key for the model you use as default:
3. Optional: request headers
The client sends:- Authorization: Bearer
<model-specific key> - HTTP-Referer: NEXT_PUBLIC_SITE_URL or http://localhost:3000
- X-Title: Scriptonia Platform
Usage and Costs
Where OpenRouter is used
- Idea: processIdea → one chat completion (JSON)
- Intent: refineIntent → one chat completion (JSON)
- Platform: selectPlatform → one chat completion (JSON)
- Execute: executeX402Workflow → many callOpenRouter / createChatCompletion calls (platform-templates: per-file and for review/dedup). Model is typically GROK
Billing
- OpenRouter bills per token by model
- Check OpenRouter pricing and your dashboard
- Scriptonia does not set rate limits; to avoid surprise cost, use OpenRouter or app-level limits in production
Reducing cost
- Use a cheaper model for Idea/Intent/Platform: set DEFAULT_MODEL=GEMINI or QWEN and ensure the corresponding key is set
- Execution can still call callOpenRouter(…, ‘GROK’, …) explicitly
- In
lib/openai.ts, you can pass a modelType into processIdea, refineIntent, selectPlatform where the function accepts it - Execution’s generateFileContentWithAgent uses callOpenRouter(…, ‘GROK’, …); changing that would require a code edit
Verification
- Set OPENROUTER_API_KEY_GROK4 (or the key for DEFAULT_MODEL) and DATABASE_URL
- Run
npm run devand submit an Idea on the home page - You should get analysis and clarifying questions
- If that works, Intent, Platform, and Execute are using the same client
- Any failure will show in server logs as OpenRouter API error or a missing-key error