-
Notifications
You must be signed in to change notification settings - Fork 0
Using OpenRouter
Griffen Fargo edited this page Jan 29, 2026
·
1 revision
OpenRouter is a unified API that provides access to multiple AI models from different providers (OpenAI, Anthropic, Google, Meta, etc.) through a single endpoint. This is useful for:
- Cost optimization - Compare prices across providers
- Model flexibility - Switch between models without changing code
- Fallback options - Use alternative models if the primary is unavailable
- Access to exclusive models - Some models are only available through OpenRouter
- Sign up at openrouter.ai
- Go to Keys and create a new API key
- Copy your key (starts with
sk-or-v1-...)
Option A: Project Config (.coco.config.json)
{
"$schema": "https://coco.griffen.codes/schema.json",
"mode": "interactive",
"service": {
"provider": "openai",
"model": "anthropic/claude-3.5-sonnet",
"baseURL": "https://openrouter.ai/api/v1",
"authentication": {
"type": "APIKey",
"credentials": {
"apiKey": "sk-or-v1-your-key-here"
}
}
}
}Option B: Git Config (~/.gitconfig)
git config --global coco.serviceProvider openai
git config --global coco.serviceModel "anthropic/claude-3.5-sonnet"
git config --global coco.serviceBaseURL "https://openrouter.ai/api/v1"
git config --global coco.serviceApiKey "sk-or-v1-your-key-here"Option C: Environment Variables
export COCO_SERVICE_PROVIDER=openai
export COCO_SERVICE_MODEL="anthropic/claude-3.5-sonnet"
export COCO_SERVICE_BASE_URL="https://openrouter.ai/api/v1"
export COCO_SERVICE_API_KEY="sk-or-v1-your-key-here"Option D: XDG Config (~/.config/coco/config.json)
{
"service": {
"provider": "openai",
"model": "anthropic/claude-3.5-sonnet",
"baseURL": "https://openrouter.ai/api/v1",
"apiKey": "sk-or-v1-your-key-here"
}
}git add .
coco -i{
"service": {
"provider": "openai",
"model": "anthropic/claude-3.5-sonnet",
"baseURL": "https://openrouter.ai/api/v1",
"tokenLimit": 4096,
"temperature": 0.32,
"maxConcurrent": 12,
"minTokensForSummary": 800,
"maxFileTokens": 2000,
"authentication": {
"type": "APIKey",
"credentials": {
"apiKey": "sk-or-v1-your-key-here"
}
}
}
}OpenRouter allows you to set custom headers for tracking:
{
"service": {
"provider": "openai",
"model": "anthropic/claude-3.5-sonnet",
"baseURL": "https://openrouter.ai/api/v1",
"fields": {
"defaultHeaders": {
"HTTP-Referer": "https://github.com/your-org/your-repo",
"X-Title": "Coco Git Assistant"
}
},
"authentication": {
"type": "APIKey",
"credentials": {
"apiKey": "sk-or-v1-your-key-here"
}
}
}
}Make sure your API key:
- Starts with
sk-or-v1- - Has sufficient credits in your OpenRouter account
- Is correctly set in your config
Check the model name format:
- Use the full model ID from OpenRouter (e.g.,
anthropic/claude-3.5-sonnet) - Don't use OpenAI-specific model names (e.g., use
openai/gpt-4onot justgpt-4o)
OpenRouter has rate limits per model. If you hit limits:
- Check your OpenRouter dashboard
- Consider upgrading your plan
- Use a different model temporarily
Monitor your usage:
- Visit OpenRouter Activity
- Set up budget alerts in your account settings
- Use cheaper models for development, premium for production
You can easily switch models without changing your config structure:
# Try different models
coco --service.model="google/gemini-pro-1.5"
coco --service.model="meta-llama/llama-3.1-70b-instruct"
coco --service.model="anthropic/claude-3.5-sonnet"- Single API Key - One key for all providers
- Unified Billing - One invoice for all usage
- Easy Switching - Change models without reconfiguring
- Cost Comparison - See which models are most cost-effective
- Fallback Options - Automatically retry with different models
- Access to Exclusive Models - Some models only available through OpenRouter