Model providers

Using OpenRouter with OpenClaw

3 min read

Browse more in Model providers.

All model providers guides →

This guide shows you how to wire OpenRouter into OpenClaw so your agents call models through OpenRouter’s unified API. You’ll walk through onboarding with the CLI, setting the OpenRouter API key, and pointing your default agent model at OpenRouter.

By the end, your OpenClaw setup will send requests through OpenRouter with sane defaults you can later tune per model.

Prerequisites

  • An OpenRouter account with an API key that starts with `sk-or-...`
  • An existing OpenClaw installation with access to the `openclaw` CLI
  • Network access from your OpenClaw environment to `https://openrouter.ai/api/v1`

Steps

  1. 1

    Onboard OpenRouter with the OpenClaw CLI

    Start by letting OpenClaw know you want to use OpenRouter as a provider. The onboard command wires up provider metadata and prepares your config so later model commands work as expected.

    bash
    openclaw onboard --auth-choice openrouter-api-key
  2. 2

    Set your OpenRouter API key in the environment

    OpenClaw reads your OpenRouter credentials from an environment variable, so you don’t hardcode secrets in code. ` key from your OpenRouter dashboard or requests will fail with auth errors.

    json
    {
      env: { OPENROUTER_API_KEY: "sk-or-..." },
      agents: {
        defaults: {
          model: { primary: "openrouter/auto" },
        },
      },
    }
  3. 3

    Configure your default agent to use OpenRouter auto routing

    Point the default agent model at `openrouter/auto` so new agents immediately route through OpenRouter without extra per-agent config. This uses OpenRouter’s automatic model selection until you decide to pin a specific provider/model combo.

    json
    {
      env: { OPENROUTER_API_KEY: "sk-or-..." },
      agents: {
        defaults: {
          model: { primary: "openrouter/auto" },
        },
      },
    }
  4. 4

    Switch to a specific OpenRouter model when you’re ready

    Once you know which model you want, switch from `openrouter/auto` to a concrete model reference. This keeps routing predictable and lets you take advantage of provider-specific behavior while still going through OpenRouter.

    bash
    openclaw models set openrouter/<provider>/<model>

Configuration

OptionDescriptionExample
OPENROUTER_API_KEYThe API key OpenClaw uses to authenticate requests to OpenRouter’s unified API.sk-or-abc1234567890
agents.defaults.model.primaryThe default model reference for agents; set this to an OpenRouter route like `openrouter/auto` or `openrouter/<provider>/<model>`.openrouter/auto

Troubleshooting

Requests through OpenRouter fail with authentication errors or 401 responses.

OpenRouter uses a Bearer token with your API key under the hood, so a bad or missing `OPENROUTER_API_KEY` breaks every call. ` value and that your process inherits it before starting OpenClaw.

Model calls don’t use the OpenRouter-specific headers or Anthropic cache markers you expect.

ai/api/v1`. If you repoint the OpenRouter provider at another proxy or base URL, those OpenRouter-specific headers and cache markers are not injected, so revert to the official OpenRouter endpoint if you need that behavior.

Frequently asked questions

Powered by Mem0

Add persistent memory to OpenClaw

Official Mem0 plugin for OpenClaw keeps context across chats and tools. Smaller prompts, lower cost, better continuity for your agents.

More in Model providers