Why Use OpenRouter?
- Single API Key: Access models from multiple providers
- Automatic Fallback: Configure fallback models if primary is unavailable
- Model Comparison: Test different models without multiple integrations
- Cost Optimization: Choose the best model for your budget
- No Vendor Lock-in: Switch between providers seamlessly
Setup
1. Get API Key
- Visit OpenRouter
- Sign up or log in
- Navigate to API Keys
- Create a new API key
- Copy the key (starts with
sk-or-v1-)
2. Configure Weaver
Option A: Configuration File Add to~/.weaver/config.json:
.env:
Model Selection
OpenRouter uses provider prefixes in model names:Popular Models
| Model ID | Provider | Description |
|---|---|---|
anthropic/claude-3.5-sonnet | Anthropic | Latest Claude Sonnet |
openai/gpt-4-turbo | OpenAI | GPT-4 Turbo |
google/gemini-pro-1.5 | Gemini Pro | |
meta-llama/llama-3.1-70b-instruct | Meta | Llama 3.1 70B |
deepseek/deepseek-chat | DeepSeek | DeepSeek V3 |
Model Discovery
Find available models:Configuration Options
OpenRouter API key (required)
OpenRouter API endpoint
HTTP/HTTPS proxy URL for API requests (optional)
Automatic Provider Detection
Weaver automatically uses OpenRouter when model names include:openrouter/prefixanthropic/prefixopenai/prefixmeta-llama/prefixdeepseek/prefixgoogle/prefix
pkg/providers/http_provider.go:372-380
Example
anthropic/.
Fallback Behavior
If no specific provider is configured, Weaver falls back to OpenRouter:Model Parameters
Configure model behavior:Maximum tokens in response
Controls randomness (0.0 = deterministic, 2.0 = very random)
Usage Examples
Using Different Providers
Cost Optimization
Switch between models based on task complexity:Model Comparison
Test the same prompt with different models:Implementation Details
Weaver uses the HTTPProvider for OpenRouter:- OpenAI-compatible API format
- Standard
/chat/completionsendpoint - Automatic model namespace handling
- Tool calling support
pkg/providers/http_provider.go
Tool Calling
OpenRouter supports tool calling for compatible models:pkg/providers/http_provider.go:69-72
Pricing
OpenRouter uses per-token pricing that varies by model:- View pricing at OpenRouter Pricing
- Pricing shown in USD per 1M tokens
- Some models offer free tiers
- Billing is usage-based
Check Costs
Troubleshooting
API Key Issues
Common Errors
401 Unauthorized
401 Unauthorized
404 Model Not Found
404 Model Not Found
- Verify model ID is correct (include provider prefix)
- Check available models
- Some models require allowlist access
429 Rate Limit
429 Rate Limit
- OpenRouter has rate limits per model
- Implement exponential backoff
- Consider distributing load across multiple models
402 Insufficient Credits
402 Insufficient Credits
- Add credits to your OpenRouter account
- Check your balance at OpenRouter Dashboard
- Some models are free for testing
Advanced Features
Model Fallback
OpenRouter supports automatic fallback:Response Metadata
OpenRouter returns usage metadata:UsageInfo.
Source: pkg/providers/http_provider.go:150
Next Steps
Provider Overview
Back to all providers
Model Comparison
Choose the right model