OpenClaw OpenRouter: Base URL, Model Routing and Fallback Checks
How to set up OpenClaw with OpenRouter, confirm the OpenAI-compatible endpoint, model routing, fallback behavior, API credits and common errors before scaling agent workflows.
OpenClaw with OpenRouter depends on the right base URL, model ID and fallback path.
Set OPENROUTER_API_KEY, run openclaw onboard, and use the openrouter/<author>/<slug> model ID format. The openrouter/ prefix is required in OpenClaw config even if the catalog ID looks different. Run openclaw gateway run after changes, and verify credits and model availability before long runs.
- 1 OpenClaw has built-in OpenRouter support - use openclaw onboard to configure it.
- 2 Set OPENROUTER_API_KEY in your shell or auth profile, then run openclaw onboard.
- 3 Pick OpenRouter as the provider, enter your API key, and select a model.
- 4 In OpenClaw, model IDs use the openrouter/<author>/<slug> format.
- 5 The openrouter/ prefix is required - catalog IDs without it will fail with model not found.
- 6 Run openclaw gateway run after configuration, then verify with a small test request.
- 7 Check OpenRouter Activity, model availability and credits before long agent runs.
Who this is for
Developers using OpenClaw as a coding agent and routing requests through OpenRouter for access to multiple models. If you are comparing routes, choosing a fallback model or checking why one provider path fails while another works, this guide is for you.
What OpenClaw and OpenRouter do together
OpenClaw is an open-source AI agent platform that connects to messaging channels and executes tasks. OpenRouter is an aggregator that routes model requests to underlying providers through a single OpenAI-compatible API. OpenClaw has built-in OpenRouter support - you do not need to manually configure a models.providers entry.
The key configuration points are your OpenRouter API key, the openrouter/ model ID format, and the openclaw gateway run command to apply changes. Credits, model availability and token usage are tracked in the OpenRouter Activity dashboard.
Test with a small prepaid API balance.
RutaAPI offers prepaid API credits that can help reduce surprise exposure during testing. Check live model pricing before long tasks.
Recommended setup with openclaw onboard
The easiest way to configure OpenClaw with OpenRouter is the built-in setup wizard. Run this command and follow the prompts:
openclaw onboard The wizard guides you through choosing OpenRouter as the provider, entering your API key, selecting a primary model, and configuring messaging channels.
If you already have your OpenRouter API key and want to skip the wizard, use the one-line command:
openclaw onboard --auth-choice apiKey --token-provider openrouter --token "$OPENROUTER_API_KEY" After configuration, start or restart the gateway:
openclaw gateway run
Let openclaw onboard select the current recommended model, then inspect the generated configuration. OpenRouter and OpenClaw documentation may reference different Auto model IDs across versions - for example openrouter/auto versus openrouter/openrouter/auto. Verify the value in your ~/.openclaw/openclaw.json against the OpenClaw version you have installed.
- Install or confirm OpenClaw is installed.
- Set OPENROUTER_API_KEY in your shell or use openclaw auth set for keychain storage.
- Run openclaw onboard and select OpenRouter as the provider.
- Enter your OpenRouter API key when prompted.
- Select a primary model in the wizard — openclaw onboard will suggest the current default for your installed version.
- Add fallback models if you want a backup path.
- Run openclaw gateway run to start or restart the gateway.
- Send a small test request to confirm the setup works.
- Check OpenRouter Activity dashboard for live token usage and credits.
Manual configuration
For advanced users who prefer to edit the config file directly, OpenClaw stores its configuration at ~/.openclaw/openclaw.json. A minimal working configuration with OpenRouter looks like this:
{
"env": {
"OPENROUTER_API_KEY": "<YOUR_OPENROUTER_API_KEY>"
},
"agents": {
"defaults": {
"model": {
"primary": "openrouter/auto"
},
"models": {
"openrouter/auto": {}
}
}
}
} Example only - verify the current model ID for your installed OpenClaw version. OpenRouter and OpenClaw documentation may reference different Auto model IDs across versions.
Set the API key as an environment variable in your shell profile instead of committing it to the config file:
export OPENROUTER_API_KEY="<YOUR_OPENROUTER_API_KEY>" After any configuration change, restart the gateway:
openclaw gateway run
OpenClaw has built-in OpenRouter support. You do not need to add a models.providers section for OpenRouter. Just set the API key and reference models using the openrouter/ prefix.
Using auth profiles for key security
Instead of storing the key directly in openclaw.json, use OpenClaw auth profiles to store the key in your system keychain. Add this to openclaw.json:
{
"auth": {
"profiles": {
"openrouter:default": {
"provider": "openrouter",
"mode": "api_key"
}
}
}
} Then set the key using the CLI:
openclaw auth set openrouter:default --key "$OPENROUTER_API_KEY" This keeps your API key out of any config file. Do not commit API keys to shared repositories or paste them into public screenshots.
Model ID format in OpenClaw
OpenClaw uses the format openrouter/<author>/<slug> for all OpenRouter models. The OpenRouter model catalog shows IDs differently - OpenClaw requires the openrouter/ prefix. This is a common source of model not found errors.
Key rules:
- Always prefix OpenRouter model IDs with
openrouter/in OpenClaw config. - Use
~authorfor latest-family aliases, e.g.openrouter/~anthropic/claude-sonnet-latest. - The catalog ID shown on openrouter.ai/models without the
openrouter/prefix will cause model not found in OpenClaw. - Model availability and IDs can change - verify the current ID at openrouter.ai/models before every significant run.
Example model IDs in OpenClaw format (verify before use):
openrouter/auto- OpenRouter Auto model, picks the most cost-effective model per request.openrouter/~anthropic/claude-sonnet-latest- Latest Claude Sonnet in the Anthropic family.openrouter/deepseek/deepseek-chat- DeepSeek Chat model.
Example only - verify the current model ID before publishing or deploying.
Primary and fallback models
Set a primary model and add fallbacks as an ordered list. OpenClaw tries them in sequence. Both the primary and every fallback must also be listed in agents.defaults.models:
{
"agents": {
"defaults": {
"model": {
"primary": "openrouter/auto",
"fallbacks": [
"openrouter/deepseek/deepseek-chat"
]
},
"models": {
"openrouter/auto": {},
"openrouter/deepseek/deepseek-chat": {}
}
}
}
} Example only - verify the current model IDs for your installed OpenClaw version. OpenRouter and OpenClaw documentation may reference different Auto model IDs across versions.
This provides an additional layer of reliability on top of OpenRouter provider-level failover. A successful fallback run is billed at that model rate. OpenRouter states that failed routing or fallback attempts are not billed, and zero-completion error responses may be protected by Zero Completion Insurance. Check the Activity dashboard for the final billing record. Do not configure fallback models that are unavailable in your account tier.
No API key found for provider 'openrouter'
The OPENROUTER_API_KEY environment variable is not set, the auth profile is missing, or the gateway is running with stale environment variables.
Confirm OPENROUTER_API_KEY is set in your shell. Run openclaw auth list to check auth profiles. Re-run openclaw onboard with your API key. Restart the gateway after any change.
401 Unauthorized on every request
The API key is missing, invalid, copied with extra whitespace, or has been revoked.
Verify the key in the OpenRouter dashboard at openrouter.ai/keys. Confirm the key starts with sk-or-. Check that the environment variable is correctly loaded in the gateway process.
402 Payment Required / insufficient credits
The OpenRouter account balance is too low for the selected model or the current request volume.
Check credits at openrouter.ai/credits. A 402 means the account cannot pay for the request - the model was not charged. Refill the account and retry.
403 Forbidden on a specific model
The key is valid but the account lacks access to the selected model, route or account tier. This can also be a guardrail block or moderation flag.
Check model availability at openrouter.ai/models. Confirm the account tier supports the model. A 403 does not necessarily mean credits - it can be a permission or moderation issue.
Incorrect model ID - model not working
The model ID is missing the openrouter/ prefix, has a wrong author-or-slug, or uses an outdated alias.
Confirm the exact model ID at openrouter.ai/models. In OpenClaw the format must be openrouter/<author>/<slug>. Use tilde-author for latest-family aliases, e.g. openrouter/~anthropic/claude-sonnet-latest. Catalog IDs without the openrouter/ prefix are not valid in OpenClaw config.
Model not available or not found
The model is not in the OpenRouter catalog, is restricted to a different tier, or the model ID has changed.
Re-verify the model ID at openrouter.ai/models before every significant run. Check account access. Test with openrouter/auto as a baseline to confirm the account is functional.
Model not added to config - no response from that model
The model ID is in the primary or fallback list but is missing from agents.defaults.models.
Add the model to agents.defaults.models in the config file, alongside setting primary or fallbacks. OpenClaw requires both the routing directive and the allowlist entry.
Credits insufficient
The OpenRouter account balance is too low for the selected model or the current request volume.
Check credits at openrouter.ai/credits. If the account balance is zero or below the model minimum, the account returns a 402 response. Refill and retry.
Gateway not restarted - changes not taking effect
The openclaw gateway run was not restarted after a config or environment variable change.
Restart the gateway after every configuration change: openclaw gateway run. A running gateway process loads config at startup and may not pick up changes automatically.
Invalid JSON in config file
Syntax errors in ~/.openclaw/openclaw.json - missing commas, mismatched quotes, duplicate fields or wrong nesting.
Validate the JSON file with a JSON linter. Confirm the file path is ~/.openclaw/openclaw.json. Check for trailing commas, unescaped characters and correct nesting of agents, defaults, model and models.
Token usage higher than expected
Large context windows, repeated tool calls, retries on the same context, or fallback model calls each generate additional costs.
Review request logs and OpenRouter Activity. Compare primary vs fallback costs. A successful fallback run is billed at that model rate. OpenRouter states that failed routing or fallback attempts are not billed, and zero-completion error responses may be protected by Zero Completion Insurance. Check the Activity dashboard for the final billing record.
Built-in OpenRouter provider vs other gateways
There are two distinct setup paths for OpenClaw model routing:
OpenClaw built-in OpenRouter provider
- Use
openclaw onboardand select OpenRouter. - Provider is OpenRouter; API key is
OPENROUTER_API_KEY. - Model IDs use the
openrouter/<author>/<slug>format. - No
models.providersconfiguration needed.
Third-party OpenAI-compatible gateway
- May require a manual Base URL and a different API key.
- Model aliases are provider-specific and may not use the
openrouter/format. - Provider-level error handling, routing, credits and model availability differ from OpenRouter.
RutaAPI is an independent alternative gateway. It is not OpenRouter, and the OpenRouter onboarding steps above do not configure RutaAPI. RutaAPI setup and routing rules are separate from OpenClaw OpenRouter integration.
Test with a small prepaid API balance.
RutaAPI offers prepaid API credits that can help reduce surprise exposure during testing. Check live model pricing before long tasks.
Monitoring and credits
Track OpenClaw usage through the OpenRouter Activity dashboard at openrouter.ai/activity. This shows:
- Token usage and cost per model.
- Request counts and response codes.
- Request counts and response codes, including any routing or fallback attempts.
- Current credits balance.
- Per-model availability status.
OpenClaw token usage can grow quickly because it sends full conversation history on each turn, includes file reads and tool outputs in the prompt, and retries failed requests with the same context. Monitor the Activity dashboard during early test runs and compare token counts against your expectations before scaling.
A successful fallback run is billed at that model rate. OpenRouter states that failed routing or fallback attempts are not billed, and zero-completion error responses may be protected by Zero Completion Insurance. Check the Activity dashboard for the final billing record.
Security checklist
- Store the OpenRouter API key in an environment variable or via
openclaw auth set- not in the config file or any committed source. - Do not paste real API keys into public screenshots or shared documents.
- Use the minimum required permission scope when generating API keys.
- Review file and shell tool permissions in OpenClaw configuration - OpenClaw can execute commands on your machine.
- Conversation history may be logged by model providers; avoid including sensitive credentials or proprietary code in prompts.
- Sanitize untrusted inputs to reduce prompt injection risk.
- OpenRouter dashboard
- credits balance, route access and model catalog
- OpenRouter /v1/models
- model availability, exact IDs and pricing per model
- OpenClaw config
- base URL, API key and provider routing configuration
- Request logs
- request IDs, token counts, model IDs and retries
FAQ
Does OpenClaw support OpenRouter?
Yes. OpenClaw has built-in OpenRouter support. The recommended way to configure it is to run openclaw onboard and select OpenRouter as the provider. OpenClaw does not need manual models.providers configuration for OpenRouter.
What model ID format does OpenClaw use for OpenRouter?
OpenClaw requires the openrouter/ prefix. Format: openrouter/<author>/<slug>. Use tilde-author for latest-family aliases, e.g. openrouter/~anthropic/claude-sonnet-latest. Without the openrouter/ prefix, OpenClaw returns model not found even if the catalog ID is valid on openrouter.ai/models.
Where should I store the OpenRouter API key?
The safest options are: (1) set it as an environment variable in your shell profile, (2) use openclaw auth set to store it in your system keychain via an auth profile. Both keep the key out of your openclaw.json config file and out of any shared or committed files.
Can OpenClaw use fallback models?
Yes. Set a primary model and add fallback models to the fallbacks array. Both the primary and every fallback must also be listed in agents.defaults.models. OpenClaw tries them in order. A successful fallback run is billed at that model rate. OpenRouter states that failed routing or fallback attempts are not billed, and zero-completion error responses may be protected by Zero Completion Insurance.
Why does a model work in OpenRouter but not in OpenClaw?
The most common reason is a missing openrouter/ prefix in the model ID. OpenClaw requires the full openrouter/<author>/<slug> format, which is different from the catalog ID shown on openrouter.ai/models. Verify the exact OpenClaw-format model ID before configuring.
Do I need to configure models.providers for OpenRouter?
No. OpenClaw has built-in OpenRouter support. You do not need to add a models.providers section for OpenRouter. Set OPENROUTER_API_KEY, choose your model IDs in the openrouter/ format, and run openclaw gateway run.
Do failed requests to OpenRouter cost credits?
OpenRouter states that failed routing or fallback attempts are not billed, and zero-completion error responses may be protected by Zero Completion Insurance. A successful request - even if it returns an error from the model - is typically billed. Check the OpenRouter Activity dashboard to see exactly which requests were charged.