Installation
The OpenRouter client is included in the core Koog library. No additional dependencies required.Quick Start
Authentication
API Key Setup
Get your API key from OpenRouter.Programmatic Configuration
Available Models
OpenRouter provides access to 100+ models. Use the model ID format:provider/model-name
Popular Models
List Available Models
Code Examples
Basic Chat Completion
Automatic Fallback
Define multiple models for automatic failover:Cost Optimization
Route to the cheapest available model:Function Calling
Structured Output
Streaming Responses
Provider-Specific Routing
Route to specific provider preferences:Embeddings
Model Comparison
Compare responses from different models:Advanced Configuration
Custom Parameters
Transforms
Apply transformations to requests:User Tracking
Key Features
Unified API
- Single integration for 100+ models
- Consistent interface across providers
- Automatic format conversion
Automatic Failover
- Fallback chain when primary model fails
- Load balancing across providers
- Uptime optimization
Cost Management
- Compare prices across providers
- Route to cheapest available model
- Usage tracking and credits
Provider Selection
- Prefer providers by priority
- Exclude providers you don’t want
- Privacy controls (data collection policies)
Pricing
OpenRouter charges per token based on the underlying provider:- Free models: Available (with rate limits)
- Paid models: Provider pricing + small markup
- Credits system: Pre-pay for usage
Best Practices
- Set up fallbacks for production reliability
- Use free models for development
- Compare models for your specific use case
- Monitor costs through the dashboard
- Set spending limits to control budget
- Choose models carefully - capabilities vary widely
Advantages
- No vendor lock-in: Switch providers easily
- Access free models: Many open-source options
- Experiment freely: Try models without multiple API keys
- Automatic failover: Better reliability
- Cost optimization: Route to cheapest suitable model
Limitations
- Additional latency: Routing adds overhead
- Markup on pricing: Slightly more expensive than direct
- Rate limits: Shared across all users
- Model availability: Can vary by time/region
- No moderation API: Not all provider features exposed