Router Desk

HomeClaude Code on OpenRouter

Claude Code on OpenRouter

Claude Code keeps talking the Anthropic protocol. OpenRouter is the gateway in front of Anthropic’s providers.

Updated 2026-09-27

OpenRouter’s cookbook says this setup is only guaranteed with Anthropic’s first-party provider. Set that provider first if you want the path they test. Failover across Anthropic providers is the availability reason they give. Spend limits and the activity dashboard are the team reasons.

Environment

export OPENROUTER_API_KEY="sk-or-v1-..."
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
  • The base URL includes https:// and stops at /api. Do not add /v1.
  • Define the key before ANTHROPIC_AUTH_TOKEN expands it. Otherwise the token is empty.
  • ANTHROPIC_API_KEY must be an empty string so Claude Code does not send the key as a direct Anthropic credential.
  • Install Claude Code with Anthropic’s install script or npm i -g @anthropic-ai/claude-code, then open a new terminal.

The key in a shell profile is a plaintext secret. Keep it out of git. Sonnet 5 was $2 / $10 per million tokens on 27 Sep 2026. That is the rate a long Claude Code session will approach if Sonnet 5 is the selected model.

Questions

What base URL does Claude Code use?

https://openrouter.ai/api

Which variable holds the OpenRouter key?

ANTHROPIC_AUTH_TOKEN. Leave ANTHROPIC_API_KEY empty.

Will this work with DeepSeek inside Claude Code?

The cookbook guarantees Anthropic first-party routing. Other slugs are outside that guarantee.

  • OpenCode and OpenRouter

    OpenCode is an open-source coding agent. Connect OpenRouter with /connect in the terminal, or the same credentials in the desktop app.

  • Claude Sonnet 5 pricing

    Claude Sonnet 5 was $2 input and $10 output per million tokens on 27 Sep 2026. Batch is $1 and $5. The slug is anthropic/claude-sonnet-5.

  • OpenRouter MCP

    The OpenRouter MCP server is https://mcp.openrouter.ai/mcp. It lets a coding agent read models, prices, and your credits after an OAuth login.

  • OpenRouter API URL

    The OpenRouter base URL is https://openrouter.ai/api/v1. Chat calls go to /chat/completions with a Bearer key.

Sources