Skip to content

One Key to Rule Them All: Setting Up OpenRouter

I used to spend way too much time managing different API keys for every new model I wanted to try. One day I was testing Claude, the next I was back on GPT-4, and my config files were a total mess of environment variables and different base URLs. It felt like I was doing more admin work than actual coding.

Then I switched to OpenRouter. It puts every major model behind a single API, which makes life so much easier. Since it uses the OpenAI format, you can swap models just by changing a string in your config. Here is how I set it up with openclaw to keep things simple.

  • An OpenRouter account with a generated API key.
  • The openclaw CLI installed on your local machine.

You can get this running in about two minutes. Follow these two steps to link your account and set your default model.

1. Authenticate the CLI

Run this command in your terminal. Replace the variable with your actual key if you haven’t exported it yet.

Terminal window
openclaw onboard --auth-choice apiKey --token-provider openrouter --token "$OPENROUTER_API_KEY"

2. Update your configuration

Open your config file and add the OpenRouter details. I recommend starting with Claude 3.5 Sonnet as your primary model because it handles coding tasks extremely well.

{
env: { OPENROUTER_API_KEY: "sk-or-..." },
agents: {
defaults: {
model: { primary: "openrouter/anthropic/claude-sonnet-4-5" },
},
},
}

If things aren’t working right away, check these two common issues:

  • Authentication Errors: OpenRouter uses a Bearer token. If you get a 401 error, make sure your key starts with sk-or- and that you have enough credits in your account.
  • Model Name Typos: OpenRouter requires a specific format: openrouter/<provider>/<model>. If you miss the provider part, the request will fail. Also, ensure you are using the exact slug found in their model list.

If you hit a wall that isn’t covered here, you can ask the AI Setup Assistant for help.

OpenClaw

OpenClaw Expert

Still stuck?

If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.