Skip to main content
Watch: I Built an AI App Without Leaving Databricks

Setup guide - Documented by OpenRouter

Use OpenRouter in Claude Code

OpenRouter publishes an official Claude Code guide: point ANTHROPIC_BASE_URL at OpenRouter's Anthropic-compatible endpoint (https://openrouter.ai/api), pass the OpenRouter key as ANTHROPIC_AUTH_TOKEN and blank out ANTHROPIC_API_KEY. You can override each model class with OpenRouter slugs.

Last verified 10 steps2 official sources

Steps

  1. Step 1.

    Install Claude Code (macOS, Linux, WSL).

    Terminal
    curl -fsSL https://claude.ai/install.sh | bash
  2. Step 2.

    Or install with npm (requires Node.js 18 or newer).

    Terminal
    npm install -g @anthropic-ai/claude-code
  3. Step 3.

    Add these environment variables to your shell profile (~/.zshrc or ~/.bashrc). ANTHROPIC_API_KEY must be explicitly empty.

    Terminal
    export OPENROUTER_API_KEY="<your-openrouter-api-key>"
    export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
    export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
    export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty
    export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 # Optional: enables the gateway model picker
  4. Step 4.

    Reload your shell so the new values are live.

    Snippet
    source ~/.zshrc # or ~/.bashrc, or open a new terminal
  5. Step 5.

    Alternative: put the same values in a project-level .claude/settings.local.json in your project root (do not commit your key).

    JSON
    {
      "env": {
        "ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
        "ANTHROPIC_AUTH_TOKEN": "<your-openrouter-api-key>",
        "ANTHROPIC_API_KEY": "",
        "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
      }
    }
  6. Step 6.

    If you previously logged in to Claude Code with an Anthropic account, run /logout once, then quit and relaunch claude.

    Snippet
    > /logout
  7. Step 7.

    Start a session in your project.

    Terminal
    cd /path/to/your/project
    claude
  8. Step 8.

    Verify with /status. The output should name ANTHROPIC_AUTH_TOKEN and the OpenRouter base URL.

    Snippet
    > /status
    Auth token: ANTHROPIC_AUTH_TOKEN
    Anthropic base URL: https://openrouter.ai/api
  9. Step 9.

    Optional: route each Claude Code model class to a specific OpenRouter model.

    Terminal
    export ANTHROPIC_DEFAULT_FABLE_MODEL="~anthropic/claude-fable-latest[1m]"
    export ANTHROPIC_DEFAULT_OPUS_MODEL="~anthropic/claude-opus-latest[1m]"
    export ANTHROPIC_DEFAULT_SONNET_MODEL="~anthropic/claude-sonnet-latest[1m]"
    export ANTHROPIC_DEFAULT_HAIKU_MODEL="~anthropic/claude-haiku-latest"
    export CLAUDE_CODE_SUBAGENT_MODEL="~anthropic/claude-opus-latest[1m]"
  10. Step 10.

    Optional: enable the /fast command (requires Claude Code v2.1.96 or newer). Pin ANTHROPIC_DEFAULT_OPUS_MODEL to a specific Opus id such as anthropic/claude-opus-5 for fast mode to actually apply.

    Terminal
    export CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1

Caveats

  • OpenRouter's own warning: Claude Code with OpenRouter is only guaranteed to work with the Anthropic first-party provider. It recommends setting Anthropic 1P as the top-priority provider, and notes Claude Code may not work correctly with non-Anthropic models.
  • The base URL is https://openrouter.ai/api (no /v1). This is the Anthropic Messages-compatible endpoint, not the OpenAI-compatible /api/v1.
  • Do not put these variables in a project .env file. The native Claude Code installer does not read standard .env files.
  • Ordering matters: OPENROUTER_API_KEY must be defined before ANTHROPIC_AUTH_TOKEN expands it, or every request fails with an auth error.
  • Fable is not offered in /model by default when pointed at OpenRouter. Setting ANTHROPIC_DEFAULT_FABLE_MODEL is the only way to make it selectable.
  • /fast with the ~anthropic/claude-opus-latest alias reports "Fast mode ON" but sends no speed parameter. Pin a concrete Opus id to get fast mode.
  • Claude Code assumes a 200k context window unless the model name ends in [1m].

FAQ

How do I use OpenRouter in Claude Code?

OpenRouter publishes an official Claude Code guide: point ANTHROPIC_BASE_URL at OpenRouter's Anthropic-compatible endpoint (https://openrouter.ai/api), pass the OpenRouter key as ANTHROPIC_AUTH_TOKEN and blank out ANTHROPIC_API_KEY. You can override each model class with OpenRouter slugs.

Which OpenRouter model ids work in Claude Code?

The official docs read for this guide list ~anthropic/claude-fable-latest[1m], ~anthropic/claude-opus-latest[1m], ~anthropic/claude-sonnet-latest[1m], ~anthropic/claude-haiku-latest, anthropic/claude-opus-5, anthropic/claude-opus-4.8, anthropic/claude-opus-4.7, anthropic/claude-opus-4.6, openrouter/auto and openrouter/pareto-code. Requests go to https://openrouter.ai/api.

Is this an official OpenRouter and Claude Code setup?

OpenRouter documents this setup in its own docs. It was last checked against 2 official pages on October 17, 2026.

Sources

Last verified against 2 official pages.

Newsletter

New models, set up the day they ship

One email per week. New model releases, the coding tools that support them and how to wire them up.