---
title: "Claude Code + OpenRouter: setup, model routing and what happens to your code — Aventail™ Guides"
url: https://aventail.co.uk/guides/claude-code-openrouter
description: "Run Claude Code through OpenRouter's Anthropic-compatible endpoint: the three variables, model overrides, how to check the route, and where your prompts go."
lang: en-GB
---

Skip to content

Aventail™ investigation into UK government AI dependence featured in Computer Weekly. Read the story: https://aventail.co.uk/newsroom/computer-weekly-uk-government-ai-dependency

All guides (https://aventail.co.uk/guides)

# Claude Code + OpenRouter: setup, model routing and what happens to your code

16 November 2026 13 min read

Run Claude Code through OpenRouter's Anthropic-compatible endpoint: the three variables, model overrides, how to check the route, and where your prompts go.

Claude Code runs through OpenRouter with three environment variables and no local proxy. OpenRouter exposes an endpoint that speaks Anthropic's Messages API, so you set `ANTHROPIC_BASE_URL` to `https://openrouter.ai/api`, put your OpenRouter key in `ANTHROPIC_AUTH_TOKEN`, and set `ANTHROPIC_API_KEY` to an empty string.

You pay with OpenRouter credits, so no Anthropic subscription is needed. Two limits apply. OpenRouter says the pairing is only guaranteed to work with Claude models on the Anthropic first-party provider. Anthropic says it does not support routing Claude Code to non-Claude models through any gateway. Unlike the local pairings in this series, every prompt also leaves your machine: first to OpenRouter, then to whichever provider serves the model.

| | Claude Code through OpenRouter, as of 15 November 2026 |
| --- | --- |
| Base URL | `https://openrouter.ai/api` |
| Credential | OpenRouter API key in `ANTHROPIC_AUTH_TOKEN`; `ANTHROPIC_API_KEY` set to `""` |
| Local proxy | None. Claude Code speaks its own protocol to OpenRouter |
| Models OpenRouter guarantees | Claude models served by the Anthropic first-party provider |
| Other models | The endpoint accepts them. OpenRouter does not guarantee them; Anthropic does not support them |
| Price | Provider token prices with no markup, plus a 5.5% fee ($0.80 minimum) when you buy credits |
| Does OpenRouter store prompts | No, unless you opt in. It stores request metadata such as token counts and latency |
| Does the provider store or train on prompts | Depends on the endpoint. You filter providers in OpenRouter's privacy settings |
| Zero data retention | Enforced per model group, per guardrail or per request. It removes the Anthropic first-party endpoint |
| Region control | `eu.openrouter.ai` and `us.openrouter.ai`, on the Business and Enterprise plans |

## What you need

| | Minimum | Notes |
| --- | --- | --- |
| Claude Code | Any current version | `/fast` through OpenRouter needs v2.1.96 or newer |
| OpenRouter account | An API key from openrouter.ai/settings/keys | Keys start with `sk-or-v1-` |
| Credits | Any balance | The 5.5% fee is charged when you buy credits |
| Node.js | Not needed for the native installer | 18 or newer if you install with npm |
| Anthropic account | Not needed | If you signed in to Claude Code before, you will run `/logout` once |

## Step 1: install Claude Code

macOS, Linux and WSL:

`curl -fsSL https://claude.ai/install.sh | bash`

Windows PowerShell:

`irm https://claude.ai/install.ps1 | iex`

With npm:

`npm install -g @anthropic-ai/claude-code`

## Step 2: point Claude Code at OpenRouter

Add these lines to your shell profile (`~/.zshrc` or `~/.bashrc` ), as OpenRouter's Claude Code guide gives them:

`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`

Reload the shell with `source ~/.zshrc` or open a new terminal. Three details decide whether this works:

- **Use** `**ANTHROPIC_AUTH_TOKEN**` **for the key.** Claude Code sends it as `Authorization: Bearer`, which is what OpenRouter reads. `ANTHROPIC_API_KEY` goes out as `x-api-key` and is treated as a direct Anthropic credential.
- **Set** `**ANTHROPIC_API_KEY**` **to an empty string.** If it holds a real Anthropic key, Claude Code may authenticate against Anthropic directly.
- **Define** `**OPENROUTER_API_KEY**` **before the line that uses it.** If a secrets manager injects it later, the token expands to an empty string and every request fails with an auth error.

The key sits in plain text in your profile. OpenRouter suggests reading it from the OS keychain instead, for example on macOS: `export OPENROUTER_API_KEY="$(security find-generic-password -s openrouter -w)"`.

## Step 3: or set it for one project

Put the same values in `.claude/settings.local.json` in the project root:

`{`
`"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"`
`}`
`}`

Use `settings.local.json`, and add it to your gitignore if you create it by hand. A project's `.claude/settings.json` is committed and shared with everyone who clones the repository. A plain `.env` file does nothing here, because the native Claude Code installer does not read one. When a shell export and a settings file set the same variable, the settings file wins.

For the VS Code extension, Anthropic's docs say to put the two gateway variables in `claudeCode.environmentVariables` in VS Code's user settings, because the extension checks credentials from that setting before it launches.

## Step 4: clear the old login and start

If you were signed in to Claude Code with an Anthropic account, run `/logout` once, quit, and start again. A cached login beside a gateway credential causes auth-conflict warnings and model-not-found errors.

`cd /path/to/your/project`
`claude`

## Step 5: choose the models

Claude Code asks for a model by role. Point each role at an OpenRouter model:

`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]"`

- The leading `~` is an OpenRouter "latest" alias. It resolves to the newest model in that family, so the line does not go stale.
- `[1m]` tells Claude Code the model has a 1M-token window. OpenRouter's guide says that without it Claude Code assumes 200K and compacts early. OpenRouter strips the marker before routing.
- The Haiku variable also sets the model for Claude Code's background work, such as session titles.
- Fable is not offered in `/model` by default when Claude Code points at OpenRouter. Setting `ANTHROPIC_DEFAULT_FABLE_MODEL` is the only way to make it selectable.
- With `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`, `/model` also lists a curated set of OpenRouter's highest-ranked models. It is not the full catalogue, and some entries route to non-Anthropic providers.

## Step 6: check where the request went and which model answered

Test the endpoint before you open a repository. This is the check from Anthropic's gateway docs, with an OpenRouter model slug:

`curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \`
`-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \`
`-H "anthropic-version: 2023-06-01" \`
`-H "content-type: application/json" \`
`-d '{"model": "anthropic/claude-sonnet-5.5", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'`

A JSON body that starts with `{"id":"msg_` means the URL and key work. A `401` means the key was rejected.

Inside Claude Code, run `/status`. You should see:

`Auth token: ANTHROPIC_AUTH_TOKEN`
`Anthropic base URL: https://openrouter.ai/api`

If the `Auth token` line names `ANTHROPIC_API_KEY`, or a `Login method` line names a Claude account, the variables did not reach the session.

`/status` proves the route to OpenRouter. It does not show which provider served the request, because Claude Code treats any gateway as the Claude API and cannot see behind it. For that, open the OpenRouter Activity dashboard at openrouter.ai/activity and read the model column, or open a single generation in Logs to see the provider, token counts and cost.

## What works and what does not through OpenRouter

Works: chat, file edits, commands and the agent loop. OpenRouter passes thinking blocks and native tool use through. The Claude Code GitHub Action and the Agent SDK work with the same variables. `/fast` works on supported models once you set `CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1`.

Does not work, or works differently:

- **Non-Claude models are at your own risk.** OpenRouter's guide states the pairing is only guaranteed to work with the Anthropic first-party provider, and that Claude Code may not work correctly with other providers. Anthropic's gateway docs say it does not support routing Claude Code to non-Claude models through any gateway. You can set a role variable to `openai/...` or `google/...` and the request will be sent. Nobody stands behind the result.
- **The provider can change between requests.** OpenRouter fails over between the providers that serve a Claude model, for example from Anthropic to Amazon Bedrock or Google Vertex. That keeps a session alive during an outage. It also means the data terms that apply can change mid-session unless you restrict providers.
- **Fast mode is Anthropic first-party only.** A `~latest` alias reports "Fast mode ON" but sends requests at standard speed. Pin the role to a specific supported model ID to get it.
- **claude.ai features are off.** Remote Control, voice dictation, server-managed settings and claude.ai connectors need a claude.ai login and Anthropic's own endpoint.
- **Some traffic still goes to Anthropic.** Version checks and telemetry go outside the gateway unless you set `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`. The fast-mode availability check and the WebFetch domain safety check call `api.anthropic.com` directly either way.
- **No HIPAA configuration.** Anthropic states that sessions through a gateway are not eligible for it.

## What OpenRouter and the model provider do with your prompts

Two companies see each request, and their terms differ.

| | OpenRouter | The provider behind it |
| --- | --- | --- |
| Stores prompts and responses | Not by default. Stores metadata: token counts, latency, model | Set per endpoint. OpenRouter labels each one: ZDR, Safety Retention, or Retention and Training |
| Trains on them | Only if you turn on "OpenRouter Use of Inputs/Outputs", which gives a 1% discount. Off by default | Providers that may train are not used unless you allow it in privacy settings. Paid and free models have separate switches |
| Opt-in logging | "Input & Output Logging" (beta). Stored for at least 3 months; organisation admins can read every logged request | Not applicable |
| Exceptions | All requests, including ZDR traffic, are screened for CSAM; flagged content may be kept. A small sample of prompts is categorised anonymously | "Safety Retention" endpoints may keep any request to prevent abuse, with no training |

The controls, in the order worth using them:

1. **Account privacy settings** (openrouter.ai/settings/privacy). Block providers that train, enforce ZDR per model group, and set account-wide allowed or ignored providers. These apply to every request, whatever the client sends.
2. **Guardrails.** An organisation admin can attach a guardrail to a member or an API key with a model allowlist, a provider allowlist, a budget, ZDR and allowed data regions. A guardrail can only be stricter than the account setting.
3. **Per request.** OpenRouter's `provider` object takes `zdr`, `data_collection`, `only`, `order` and `allow_fallbacks`. Claude Code has no flag for it. Its `CLAUDE_CODE_EXTRA_BODY` variable merges a JSON object into request bodies, so `{"provider":{"order":["anthropic"]}}` is the per-machine form. Neither vendor documents that pairing, so confirm it in Activity before you rely on it.

One conflict to know before you enforce ZDR. For the Anthropic model group, ZDR removes the first-party Anthropic endpoint and leaves Bedrock and Vertex. That is the opposite of OpenRouter's advice to put Anthropic first for Claude Code. For Google models served through Vertex, Google has required Safety Retention since 18 October 2026, so "ZDR only" makes most Google models unavailable.

For region control, requests sent to `https://eu.openrouter.ai` are decrypted in Europe and routed only to endpoints in the EU/EEA, the UK and Switzerland. This needs the Business or Enterprise plan, and Input & Output Logging is skipped on the regional hosts. Account and billing data may still be processed in the US.

## The same setup for a team: an approved provider under a routing rule

The steps above put a personal key in a shell profile. OpenRouter's guardrails narrow what that key can reach, and Claude Code's managed settings can pin the base URL if you run device management. Nothing in this setup keeps a sensitive repository off the cloud altogether.

Aventail ™ Connect configures Claude Code to send model requests through Aventail ™ Link, the inference engine and gateway on each machine. Routing rules are set once in Aventail ™ Control and evaluated on the device. A provider connection calls an approved cloud provider through your organisation's own account, with the key stored in Control's API key vault. Developers do not paste a provider key into the app.

Aventail ™ connects to hosted providers through your organisation's own account with that provider. Google Gemini is one, and Aventail ™ 's site names Google and Anthropic models, Kimi, DeepSeek, Mistral and Qwen. With an approved provider, the pattern is:

1. **Install Link** on each developer machine and choose Connect next to Claude in Connected apps. Claude Code uses that connection.
2. **Add the provider key** to the API key vault. This needs the Fleet Admin or Super Admin role.
3. **Tag the machines.** Rules match devices, so machines that work on sensitive repositories get their own tag and policy.
4. **Write two policies.** Sensitive machines permit only On device, with no provider and no fallback. Other machines use On device first with one fallback hop to the approved provider, or the provider first.
5. **Check Requests in Control** after a harmless prompt. If no destination is permitted, the request fails with an error.

Routing to hosted providers is in beta. The hosted Control service receives device and routing events, and does not receive prompts or responses.

## Which path to take

| | Claude Code + OpenRouter by hand | Claude Code with Aventail ™ Connect |
| --- | --- | --- |
| Who it suits | One developer, or a team happy with OpenRouter as the gateway | A team that must keep some repositories on local models |
| Setup | Three environment variables | Connect button in Link, rules in Control |
| Where prompts go | OpenRouter, then a provider it selects | Where the rule says: the device, or one approved provider on your own account |
| Who restricts providers | The account owner, in privacy settings and guardrails | An admin, in a routing policy evaluated on the device |
| Local models | No | Yes |
| Record of requests | OpenRouter Activity and Logs | Requests in Control |
| If the route is not allowed | Request fails at OpenRouter | Request fails on the device |
| Cost | Provider prices plus 5.5% on credits | Free for three devices; Starter is £50 a month excluding VAT with ten devices; provider charges on your own account |

## Frequently asked questions

**Do I need an Anthropic subscription to use Claude Code with OpenRouter?**
No. Requests are billed to your OpenRouter credits. You need an OpenRouter account and key. If you were signed in with an Anthropic account, run `/logout` once.

**Can I use GPT, Gemini or DeepSeek models in Claude Code through OpenRouter?**
The endpoint will accept the request if you set a role variable to that model's slug. OpenRouter says the integration is only guaranteed with the Anthropic first-party provider, and Anthropic does not support non-Claude models through a gateway. Expect tool-call errors on some models.

**How much does Claude Code cost through OpenRouter?**
You pay each provider's per-token price with no markup. OpenRouter charges 5.5% when you buy credits, with a $0.80 minimum. Using your own provider keys (BYOK) is free up to $25,000 of usage a month on pay-as-you-go, then 5%.

**Does OpenRouter log my source code?**
Not by default. OpenRouter states it does not store prompts or responses unless you opt in to logging, and it keeps metadata only. The provider that serves the model has its own retention terms, which is why the privacy settings matter.

**Can I use free OpenRouter models with Claude Code?**
Free variants exist and are rate limited: 50 requests a day, or 1,000 a day once you have bought at least 10 credits. They are not Anthropic models, so the compatibility warning applies, and free models have their own training switch in privacy settings.

**Why does Claude Code say the model was not found?**
Usually a credential conflict. Either a cached Anthropic login is still present (run `/logout` and relaunch) or your shell still exports a real `ANTHROPIC_API_KEY` (set it to `""` and reload). `/status` should show `ANTHROPIC_AUTH_TOKEN` and the OpenRouter base URL.

**Does it work in GitHub Actions?**
Yes. Pass the OpenRouter key as the action's `anthropic_api_key` input, and set `ANTHROPIC_BASE_URL` to `https://openrouter.ai/api` and `ANTHROPIC_AUTH_TOKEN` to the same secret in the step's `env` block.

## Related guides

- AI coding on your own models: https://aventail.co.uk/guides/ai-coding-on-your-own-models
- Claude Code + Ollama: https://aventail.co.uk/guides/claude-code-ollama
- OpenCode + OpenRouter
- Claude Code + Gemini
- Claude Code with: https://aventail.co.uk/guides/claude-code-with-aventail-connect
  Aventail: https://aventail.co.uk/guides/claude-code-with-aventail-connect
  ™: https://aventail.co.uk/guides/claude-code-with-aventail-connect Connect: https://aventail.co.uk/guides/claude-code-with-aventail-connect
- Route local models and cloud APIs: https://aventail.co.uk/guides/route-local-models-and-cloud-apis

## Sources

1. OpenRouter, Claude Code integration: https://openrouter.ai/docs/cookbook/coding-agents/claude-code-integration
2. OpenRouter blog, How to Use Claude Code with OpenRouter (updated 27 October 2026): https://openrouter.ai/blog/tutorials/claude-code-openrouter/
3. OpenRouter, Anthropic Messages API reference: https://openrouter.ai/docs/api/api-reference/anthropic-messages/create-a-message
4. OpenRouter, Data collection: https://openrouter.ai/docs/guides/privacy/data-collection
5. OpenRouter, Provider logging: https://openrouter.ai/docs/guides/privacy/provider-logging
6. OpenRouter, Zero data retention: https://openrouter.ai/docs/guides/features/zdr
7. OpenRouter, Provider routing: https://openrouter.ai/docs/guides/routing/provider-selection
8. OpenRouter, Guardrails: https://openrouter.ai/docs/guides/features/guardrails
9. OpenRouter, Input and output logging: https://openrouter.ai/docs/guides/features/input-output-logging
10. OpenRouter, In-region routing: https://openrouter.ai/docs/guides/features/in-region-routing
11. OpenRouter, FAQ (fees, BYOK, free model limits, logging): https://openrouter.ai/docs/faq
12. OpenRouter, model list API: https://openrouter.ai/api/v1/models
13. Anthropic, Other LLM gateways: https://code.claude.com/docs/en/llm-gateway
14. Anthropic, Connect Claude Code to an LLM gateway: https://code.claude.com/docs/en/llm-gateway-connect
15. Anthropic, Gateway compatibility guide: https://code.claude.com/docs/en/llm-gateway-protocol
16. Anthropic, Model configuration: https://code.claude.com/docs/en/model-config
17. Anthropic, Environment variables: https://code.claude.com/docs/en/env-vars
18. Anthropic, Feature availability: https://code.claude.com/docs/en/feature-availability
19. Anthropic, Data usage: https://code.claude.com/docs/en/data-usage
20. Aventail ™, Connect overview: https://docs.aventail.co.uk/docs/connect/overview
21. Aventail ™, Routing: https://docs.aventail.co.uk/docs/fleet/routing
22. Aventail ™, Route local models and cloud APIs: https://aventail.co.uk/guides/route-local-models-and-cloud-apis
23. Aventail ™, Pricing: https://aventail.co.uk/#pricing

All sources were read on 15 November 2026.

We use optional cookies and tracking to identify visiting companies, load our contact form, measure Google Ads download clicks and understand page use with PostHog on our homepage, Connect and How it works pages, Ollama and LM Studio comparison guides and campaign pages. Cookie policy (https://aventail.co.uk/cookies)

## Structured data

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Organization",
      "@id": "https://aventail.co.uk/#organization",
      "name": "Aventail",
      "alternateName": "Locai",
      "legalName": "Loc.ai Ltd",
      "description": "Aventail, formerly Locai, was founded in 2026 and is a graduate of Google AI First. It gives enterprises the full AI stack to adopt AI securely: a built-in inference engine, deployment of supported models across approved hardware, on-device classification and policy-based routing between those machines and approved external AI providers, central management and an employee workspace. Organisations use Aventail to put approved information to work while controlling where inference requests run.",
      "url": "https://aventail.co.uk/",
      "logo": "https://aventail.co.uk/apple-touch-icon.png",
      "email": "hello@aventail.co.uk",
      "hasCredential": [
        {
          "@type": "EducationalOccupationalCredential",
          "name": "Cyber Essentials",
          "credentialCategory": "certification",
          "url": "https://aventail.co.uk/trust#cyber-essentials"
        }
      ]
    },
    {
      "@type": "Article",
      "@id": "https://aventail.co.uk/guides/claude-code-openrouter#page",
      "url": "https://aventail.co.uk/guides/claude-code-openrouter",
      "name": "Claude Code + OpenRouter: setup, model routing and what happens to your code",
      "description": "Run Claude Code through OpenRouter's Anthropic-compatible endpoint: the three variables, model overrides, how to check the route, and where your prompts go.",
      "publisher": {
        "@id": "https://aventail.co.uk/#organization"
      },
      "headline": "Claude Code + OpenRouter: setup, model routing and what happens to your code",
      "datePublished": "2026-11-16",
      "dateModified": "2026-11-16T18:48:12.650806+00:00",
      "image": "https://aventail-ai-platform.lovable.app/images/share/og-home-v7.jpg",
      "author": {
        "@id": "https://aventail.co.uk/#organization"
      }
    },
    {
      "@type": "BreadcrumbList",
      "@id": "https://aventail.co.uk/guides/claude-code-openrouter#breadcrumb",
      "itemListElement": [
        {
          "@type": "ListItem",
          "position": 1,
          "name": "Home",
          "item": "https://aventail.co.uk/"
        },
        {
          "@type": "ListItem",
          "position": 2,
          "name": "Guides",
          "item": "https://aventail.co.uk/guides"
        },
        {
          "@type": "ListItem",
          "position": 3,
          "name": "Claude Code + OpenRouter: setup, model routing and what happens to your code",
          "item": "https://aventail.co.uk/guides/claude-code-openrouter"
        }
      ]
    }
  ]
}
```