{
  "id": 21371663,
  "title": "How to use an OpenRouter API key in Claude Code",
  "url": "https://urgent.news/2026/11/23/how-to-use-an-openrouter-api-key-in-claude-code",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-23T08:58:29.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/alwaysagent/how-to-use-an-openrouter-api-key-in-claude-code-2b9m"
  },
  "original_language": "en",
  "account": "To utilize an OpenRouter API key within Claude Code, you must configure four environment variables and log out of any Anthropic account. First, set ANTHROPIC_BASE_URL to https://openrouter.ai/api, followed by assigning your API key to ANTHROPIC_AUTH_TOKEN. Next, ensure ANTHROPIC_API_KEY is left empty as it is treated as a direct Anthropic credential and should not be included in the key. Finally, log out of any Anthropic account. These steps are outlined in OpenRouter's official Claude Code integration guide.\n\nThe base URL for OpenRouter is https://openrouter.ai/api, without the /v1. The API key is stored in the ANTHROPIC_AUTH_TOKEN variable, which Claude Code sends as Authorization: Bearer. Importantly, ANTHROPIC_API_KEY should remain empty as it is considered a direct Anthropic credential and should not be sent. The ANTHROPIC_API_KEY is sent as x-api-key and must stay blank.\n\nThere are two methods to configure these variables: using shell profile exports or a settings.json file. Shell variables are recommended for quick testing, while settings.json is preferred for persistent configurations. The shell profile method involves adding the exports to ~/.zshrc, ~/.bashrc, or your fish config and reloading the profile. Alternatively, you can edit ~/.claude/settings.json for project-wide configurations or .claude/settings.local.json for specific projects.\n\nOnce configured, verify the setup by running /status within Claude Code. The output should display Auth token: ANTHROPIC_AUTH_TOKEN and Anthropic base URL: https://openrouter.ai/api. If the output displays ANTHROPIC_API_KEY or a Claude account, reload the shell and restart Claude Code. Sending a prompt and checking the dashboard in the OpenRouter Activity dashboard will confirm successful configuration, with the model name appearing in the request log.",
  "summary": "Originally published at alwaysagent.app . The original is kept up to date. OpenRouter has an official Claude Code integration. Four environment variables and a logout are all it takes. This guide covers the full config, verification, model switching, costs, troubleshooting, server setups, and the open-source Claude Code Router. The short answer: four variables To use an OpenRouter API key in…",
  "key_points": [
    "Set ANTHROPICBASEURL to https://openrouter.ai/api",
    "Assign API key to ANTHROPICAUTHTOKEN variable",
    "Leave ANTHROPICAPIKEY empty in Claude Code"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}