Claude Code

Claude Code

Configure AnyRouter in Claude Code.

Claude Code is an AI coding assistant that runs in your terminal. AnyRouter connects to Claude Code through an Anthropic Messages compatible API.

Option 1: Use environment variables

If you already have Claude Code installed, just set the environment variables in your current terminal session. Get your API Key from the AnyRouter console.

Set ANTHROPIC_BASE_URL to the AnyRouter API root. Claude Code calls /v1/messages in the Anthropic Messages format, so do not append /anthropic.

On Linux / Mac, run:

bash342 B
export ANTHROPIC_BASE_URL=https://ai.cloudtay.comexport ANTHROPIC_AUTH_TOKEN=<your AnyRouter API Key>export ANTHROPIC_MODEL=gpt5.5export ANTHROPIC_DEFAULT_OPUS_MODEL=gpt5.5export ANTHROPIC_DEFAULT_SONNET_MODEL=gpt5.5export ANTHROPIC_DEFAULT_HAIKU_MODEL=gpt5.5export CLAUDE_CODE_SUBAGENT_MODEL=gpt5.5export CLAUDE_CODE_EFFORT_LEVEL=high

On Windows, run in PowerShell:

powershell342 B
$env:ANTHROPIC_BASE_URL="https://ai.cloudtay.com"$env:ANTHROPIC_AUTH_TOKEN="<your AnyRouter API Key>"$env:ANTHROPIC_MODEL="gpt5.5"$env:ANTHROPIC_DEFAULT_OPUS_MODEL="gpt5.5"$env:ANTHROPIC_DEFAULT_SONNET_MODEL="gpt5.5"$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="gpt5.5"$env:CLAUDE_CODE_SUBAGENT_MODEL="gpt5.5"$env:CLAUDE_CODE_EFFORT_LEVEL="high"

Once configured, run it in your project directory:

bash29 B
cd /path/to/my-projectclaude

For deeper reasoning, change CLAUDE_CODE_EFFORT_LEVEL to xhigh or max, but this increases token usage.

Option 2: Write to settings.json

To have Claude Code use AnyRouter on every launch, put the same environment variables in Claude Code's settings.json.

For a personal global setup, write to ~/.claude/settings.json.

json511 B
{    "effortLevel": "xhigh",    "env": {        "ANTHROPIC_BASE_URL": "https://ai.cloudtay.com",        "ANTHROPIC_AUTH_TOKEN": "<your AnyRouter API Key>",        "ANTHROPIC_MODEL": "gpt-5.5",        "ANTHROPIC_DEFAULT_OPUS_MODEL": "gpt-5.5",        "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.5",        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5.5",        "ANTHROPIC_SMALL_FAST_MODEL": "gpt-5.5",        "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "240000",        "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "85"    }}

To use AnyRouter only in the current project, write to .claude/settings.local.json in the project directory. This file is a good place for your personal key and should not be committed to Git.

Option 3: Use a separate settings file

If you often switch between model services, save AnyRouter as its own settings file, for example ~/.claude/models/anyrouter.json.

json511 B
{    "effortLevel": "xhigh",    "env": {        "ANTHROPIC_BASE_URL": "https://ai.cloudtay.com",        "ANTHROPIC_AUTH_TOKEN": "<your AnyRouter API Key>",        "ANTHROPIC_MODEL": "gpt-5.5",        "ANTHROPIC_DEFAULT_OPUS_MODEL": "gpt-5.5",        "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.5",        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5.5",        "ANTHROPIC_SMALL_FAST_MODEL": "gpt-5.5",        "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "240000",        "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "85"    }}

Pass the file with --settings at launch.

bash55 B
claude --settings "$HOME/.claude/models/anyrouter.json"

You can also add an alias to your shell config.

bash67 B
alias ccv='claude --settings "$HOME/.claude/models/anyrouter.json"'

Then run ccv in your project directory to start Claude Code with the AnyRouter settings.

Install Claude Code from scratch

1. Install Claude Code

The official Claude Code installer is recommended.

macOS / Linux / WSL

bash53 B
curl -fsSL https://claude.anyrouter/install.sh | bash

Windows PowerShell

powershell46 B
irm https://claude.anyrouter/install.ps1 | iex

You can also install with npm, which requires Node.js 18+.

bash47 B
npm install -g @anthropic-anyrouter/claude-code
bash16 B
claude --version

2. Choose a configuration method

Pick one of the methods above: environment variables, settings.json, or a separate settings file. Your AnyRouter API Key comes from the AnyRouter console.

3. Go to your project directory and run claude

bash29 B
cd /path/to/my-projectclaude

FAQ

  • 404 or endpoint not found: make sure ANTHROPIC_BASE_URL is https://ai.cloudtay.com and do not append /anthropic.
  • 401 or authentication failure: make sure ANTHROPIC_AUTH_TOKEN is set to your AnyRouter API Key. If you previously set ANTHROPIC_API_KEY, clear the old value and restart your terminal.
  • Model does not exist: use the model ID shown in the AnyRouter console.