How to Integrate OpenRouter Models in Openclaw
Quick Start
OpenRouter gives you access to hundreds of AI models through a single API. This guide shows you how to integrate OpenRouter with OpenClaw in under 5 minutes.
Configure Authentication
Set up your OpenRouter API key using the CLI onboarding wizard. Run this command in your terminal:
openclaw onboard --auth-choice apiKey --token-provider openrouter --token "$OPENROUTER_API_KEY"
Alternatively, manually edit your ~/.openclaw/openclaw.json configuration file:
{ "env": { "OPENROUTER_API_KEY": "sk-or-..." }, "agents": { "defaults": { "model": { "primary": "openrouter/anthropic/claude-sonnet-4-5" } } } }
If you are new to OpenClaw, you might also want to read about Elevated Mode for advanced permissions.
Available Models
OpenRouter provides unified access to models from Anthropic, OpenAI, Google, Meta, and more. Popular model IDs include:
- openrouter/anthropic/claude-sonnet-4
- openrouter/openai/gpt-4o
- openrouter/google/gemini-2.5-pro
- openrouter/meta-llama/llama-4-maverick
For more deployment options, check out our guide on Fly.io Deployment.
Working Example
Here is a minimal example showing how to use OpenRouter with OpenClaw:
// Request
{ "prompt": "Explain OpenRouter in one sentence", "model": "openrouter/anthropic/claude-sonnet-4" }
// Response
{ "content": "OpenRouter is a unified API gateway that provides access to hundreds of AI models with standardized pricing and routing." }
Troubleshooting & Best Practices
- API Key Format: OpenRouter keys start with sk-or-. Ensure yours matches this pattern.
- Model Routing: OpenRouter automatically handles fallbacks if a model is unavailable.
- Rate Limits: Check your OpenRouter dashboard for current rate limits and usage.
- Cost Tracking: Use the openclaw.json config to set spending limits on specific models.
OpenRouter simplifies multi-model AI workflows. With OpenClaw integration, you can switch between providers seamlessly without changing your codebase.