Skip to main content
Use your existing Claude or ChatGPT subscription with Claude Code or Codex CLI while routing requests through OpenRouter. Requests to your subscription’s provider use your plan with no OpenRouter credits or fees, and you can still use OpenRouter credits for other models. OpenRouter uses your subscription login for that request only and never stores or logs it.

Set up

Claude Code

Sign in to Claude Code with your claude.ai account using /login. Clear any existing ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, or apiKeyHelper values (such as from a previous OpenRouter API-key setup) so they do not override your claude.ai login, then point Claude Code at OpenRouter with your OpenRouter API key:
To keep this setup across terminals and background agents, add the same values to ~/.claude/settings.json. Settings in that file override shell exports, so the empty ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY entries prevent leftover shell exports from overriding your subscription. Never put your OpenRouter API key in a repository’s .claude/settings.json.
Run /status in Claude Code to confirm Anthropic base URL is https://openrouter.ai/api and your claude.ai login is active.

Codex CLI

Sign in to Codex with your ChatGPT account using codex login. Export your OpenRouter API key in your shell profile (~/.zshrc, ~/.bashrc, or PowerShell $PROFILE):
Add an OpenRouter provider block to your user-level ~/.codex/config.toml (%USERPROFILE%\.codex\config.toml on Windows). Leave out env_key and [model_providers.openrouter.auth] so Codex sends your ChatGPT login instead of replacing it. Codex ignores model_provider and model_providers in project-local .codex/config.toml files.
Start codex from a shell with OPENROUTER_API_KEY set. If you use the Codex desktop app, make OPENROUTER_API_KEY visible to GUI apps as described in the Codex Desktop App guide.

What works and what does not

Not available at all

  • Claude Desktop app: Does not read ANTHROPIC_BASE_URL or ~/.claude/settings.json, and its third-party gateway mode disables claude.ai subscriptions.
  • Cloud sessions (Claude Code on the web, Claude Tag, Codex cloud tasks): Provider-hosted cloud sessions bypass your local configuration.
  • Compliance and data residency on subscription traffic: Subscription requests always go to your provider’s standard endpoint under your plan’s terms, not HIPAA, zero data retention, or regional endpoints.

Roll back

Claude Code

Unset the variables in your current shell:
Remove ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, and any empty ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY entries from your shell profile (~/.zshrc, ~/.bashrc, or PowerShell $PROFILE), from ~/.claude/settings.json, and from any project .claude/settings.local.json. Then open a new shell and restart claude. Run /status to confirm Anthropic base URL is no longer set. If Claude Code prompts you to sign in, run /login.

Codex CLI

Remove model_provider = "openrouter" and the [model_providers.openrouter] block from ~/.codex/config.toml, then restart codex. If Codex prompts you to sign in, run codex login.