Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Claude Code can run a non-Anthropic model if you point it at a gateway that translates its requests for another provider. OpenRouter and LiteLLM both publish setup instructions for this. It is an unofficial route, not a supported configuration, and a cheaper per-token rate does not guarantee a cheaper finished task. The steps below show how each route is configured, how to confirm it is active, and what to test before you rely on it.

How the routing works

Three settings do different jobs. Confusing them is the most common reason a setup appears to connect but runs the wrong model.

  • Destination: ANTHROPIC_BASE_URL changes where Claude Code sends its requests.
  • Identity: ANTHROPIC_AUTH_TOKEN carries the gateway key. ANTHROPIC_API_KEY is the variable for a direct Anthropic key, and a leftover value there can conflict with the gateway key.
  • Model: the --model flag, a settings value, or the model environment variables choose the model. A base URL alone does not select one.

The gateway also has to accept the request format Claude Code sends. Anthropic’s gateway documentation notes that model IDs, request fields, headers and feature behavior differ between the Anthropic Messages format and the formats used by cloud providers. A gateway can forward a request successfully and still change how a feature behaves.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The support boundary

Anthropic’s gateway documentation states:

“Any gateway that exposes a supported API format works. Anthropic doesn’t endorse, maintain, or audit third-party gateway products, and doesn’t support routing Claude Code to non-Claude models through any gateway.”

OpenRouter draws the same boundary from its side. Its Claude Code integration is guaranteed only with its Anthropic first-party provider, and its guide warns that Claude Code may not work correctly with other providers. Treat both routes as experimental. When something breaks, you diagnose it yourself, and a later Claude Code update can change behavior that worked before.

Option A: OpenRouter hosted gateway

OpenRouter is a hosted gateway. Claude Code sends requests to its API with an OpenRouter key, and OpenRouter forwards them to the model you choose. As of early October 2026, its setup guide uses the base URL https://openrouter.ai/api.

Set the environment variables

Export these values in your shell, or in a shell profile (read the key-storage note below first):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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=""

Setting ANTHROPIC_API_KEY to an empty string prevents a credential precedence conflict with the gateway key.

Clear any cached Claude login

If you have signed in with a Claude account before, run /logout once inside Claude Code, quit, and relaunch it. This makes the gateway credential the one in use.

Confirm the route

Run /status and check that the base URL and the credential source match what you exported. If they do not, the session is still using another route. Fix that before you test anything.

Choose models

OpenRouter’s recommended configuration sets model variables that map Claude Code’s model classes to specific model IDs. Gateway model discovery, which fills the /model picker from the gateway, is opt-in: set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1. Model IDs change, so copy the current ones from OpenRouter’s guide rather than from older articles.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify the model that served your requests

Check the activity dashboard in OpenRouter to see which model handled each request. The label in Claude Code shows what you selected, not what the gateway actually delivered.

Store the key safely

Keep the key out of committed files. OpenRouter warns that a plaintext key in a shell profile can be committed or shared by accident. Anthropic’s gateway guide allows the credential to live in environment variables or an appropriate settings scope, and warns against putting a secret in a shared project settings file.

Option B: LiteLLM proxy you control

LiteLLM runs as a proxy on infrastructure that you or your organization manage. It holds the provider credentials, translates Claude Code’s Anthropic Messages requests into each provider’s format, and exposes the models you list. Its tutorial shows OpenAI, Gemini, Vertex AI and Azure OpenAI examples. Provider names, model names and versions change, so take the configuration from the current LiteLLM guide rather than copying a model ID from this article.

Set up the proxy and connect Claude Code

  1. Write the proxy configuration with your provider credentials and a model list. Each model entry’s name is what you will pass to Claude Code.
  2. Start the proxy and note the address it listens on.
  3. Export the proxy address and a proxy key, then select the configured model:
    export ANTHROPIC_BASE_URL="<proxy-address>"
    export ANTHROPIC_AUTH_TOKEN="<proxy-key>"
    claude --model <configured-model-name>
    
  4. To fill the /model picker from the proxy, set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1. LiteLLM documents this feature for Claude Code v2.1.129 or later.

The proxy key may grant access to every model in the configuration. If several people or tools share the proxy, LiteLLM recommends issuing virtual keys so each key reaches only the models it needs.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How the two routes compare

Factor OpenRouter (hosted) LiteLLM (self-hosted proxy)
Deployment Hosted gateway at https://openrouter.ai/api Proxy you run on infrastructure you or your organization control
Client credential OpenRouter key in ANTHROPIC_AUTH_TOKEN, with ANTHROPIC_API_KEY set empty Proxy key in ANTHROPIC_AUTH_TOKEN; virtual keys recommended for limited access
Upstream provider keys Not stated in the setup guide checked in early October 2026 Held in the proxy’s own configuration
Model selection Model variables map model classes to IDs; discovery is opt-in --model with a configured name; discovery is opt-in (Claude Code v2.1.129 or later)
Access control Not stated in the setup guide checked in early October 2026 Virtual keys limit which models a key can reach
Where prompts go Through OpenRouter; retention and logging terms not stated in the setup guide. Check the usage dashboard and logs. Through your proxy to the providers you configure

Where the workaround breaks

Translation does not establish feature parity. Test each area below before trusting a route.

  • Unrecognized model IDs. Claude Code applies its own assumptions to model IDs it does not recognize. Those assumptions can change the context size it displays and when it compacts a long session.
  • Tool calls. Test file reads, edits and shell commands. A model can produce a plausible text answer while failing to finish the tool-mediated steps that the task depends on.
  • Long sessions. Run a session long enough to approach the model’s context limit, and check whether the model’s behavior holds up near that limit.
  • Retries and repeated attempts. Watch for the same step being retried. Each retry adds cost and time.
  • Wrong account or wrong route. If requests appear on an unexpected account, run /logout, quit, relaunch, and check /status.

To return to the default Anthropic route, unset ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN and any model variables in a new shell, relaunch Claude Code, and confirm the route with /status.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a lower token rate may not mean a cheaper task

Per-token prices are only one input. Total cost depends on how many tokens a finished task consumes across every turn, including retries. The vendor documentation checked in early October 2026 contains no comparable cost or coding-quality benchmark, so compare the routes on your own work.

Cost factor Why it changes the total
Input tokens Agentic coding sessions resend a growing context on each turn.
Output tokens Long diffs and explanations are billed at the output rate.
Cached tokens Cache pricing and hit rates vary by provider, so the same session can cost differently on each route.
Reasoning tokens Where a model bills reasoning separately, those tokens add to the total.
Retries Failed or repeated requests are billed again.
Turns A cheaper model that needs more turns to finish can cost more overall.
Completion A cheap task that fails its tests still costs you the time to review and redo it.
  1. Pick two or three representative tasks from your real work, such as fixing a failing test or adding an endpoint.
  2. Run each task on the Claude route and on the alternative route, using the same repository and instructions.
  3. Record input, output, cached and reasoning tokens, retry count and turn count from each provider’s dashboard or logs.
  4. Count a run as complete only when its tests pass and the resulting diff is correct.

If you need a supported route

Anthropic’s enterprise overview lists the supported ways to reach Claude: Anthropic Console, Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform and Microsoft Foundry. They differ in billing, authentication and enterprise controls. They give access to Claude through other infrastructure. They are not a way to run non-Claude models in Claude Code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Who should use this setup

  • Reasonable fit: personal projects or disposable repositories, comparing models on tasks you can check, and learning how gateway routing behaves.
  • Poor fit: team or production workflows that need vendor support, code you are not willing to send through a third-party gateway, and cost savings you have not measured.

Vendor setup pages change. Check model IDs, discovery behavior and supported features against the current OpenRouter and LiteLLM guides each time you configure a route.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.