AgentRouter

Using AgentRouter with Claude Code

Complete guide to set up Claude Code with AgentRouter API

Using AgentRouter with Claude Code

This guide will help you configure Claude Code to use AgentRouter as your API provider.

Install Claude Code

pnpm install -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code
yarn global add @anthropic-ai/claude-code

Configure Environment Variables

Set up the environment variables to use AgentRouter's Anthropic API:

# Set AgentRouter's API base URL
export ANTHROPIC_BASE_URL=https://agentrouter.org/

# Set your AgentRouter API key (get it from https://agentrouter.org/console/token)
export ANTHROPIC_AUTH_TOKEN=sk-xxx
export ANTHROPIC_API_KEY=sk-xxx
# Set AgentRouter's API base URL
$env:ANTHROPIC_BASE_URL="https://agentrouter.org/"

# Set your AgentRouter API key (get it from https://agentrouter.org/console/token)
$env:ANTHROPIC_AUTH_TOKEN="sk-xxx"
$env:ANTHROPIC_API_KEY="sk-xxx"
# Set AgentRouter's API base URL
set ANTHROPIC_BASE_URL=https://agentrouter.org/

# Set your AgentRouter API key (get it from https://agentrouter.org/console/token)
set ANTHROPIC_AUTH_TOKEN=sk-xxx
set ANTHROPIC_API_KEY=sk-xxx

Important

Make sure to replace sk-xxx with your actual AgentRouter API token. Get your API key from AgentRouter Console.

Launch Claude Code

After configuring the environment variables, navigate to your project directory and start Claude Code:

# Navigate to your project directory
cd my-project

# Launch Claude Code
claude

Model Selection

You can control Claude Code's model choice using environment variables:

VariableDescription
ANTHROPIC_MODELPrimary model for Claude Code. Accepts a model alias (e.g., sonnet, haiku) or full model name.
ANTHROPIC_SMALL_FAST_MODELFast, low-latency model for lightweight/background operations. (Deprecated)
  • claude-sonnet-4-5-20250929
  • claude-sonnet-4-5-20250514
  • claude-haiku-4-5-20251001
  • claude-3-5-haiku-20241022
# Set primary model
export ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
# Fast model for lightweight ops (deprecated)
export ANTHROPIC_SMALL_FAST_MODEL=claude-3-5-haiku-20241022

# Launch Claude Code
claude
# Set primary model
$env:ANTHROPIC_MODEL = "claude-sonnet-4-5-20250929"
# Fast model for lightweight ops (deprecated)
$env:ANTHROPIC_SMALL_FAST_MODEL = "claude-3-5-haiku-20241022"

# Launch Claude Code
claude
# Set primary model
set ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
# Fast model for lightweight ops (deprecated)
set ANTHROPIC_SMALL_FAST_MODEL=claude-3-5-haiku-20241022

# Launch Claude Code
claude

Persist Configuration

Add the environment variables to your shell configuration file to avoid setting them manually each time:

Add to ~/.bashrc or ~/.zshrc:

export ANTHROPIC_BASE_URL=https://agentrouter.org/
export ANTHROPIC_AUTH_TOKEN=sk-xxx
export ANTHROPIC_API_KEY=sk-xxx

Add to your PowerShell profile ($PROFILE):

$env:ANTHROPIC_BASE_URL="https://agentrouter.org/"
$env:ANTHROPIC_AUTH_TOKEN="sk-xxx"
$env:ANTHROPIC_API_KEY="sk-xxx"

Note

ANTHROPIC_SMALL_FAST_MODEL is deprecated. Migrate to the recommended Haiku defaults when possible. ANTHROPIC_MODEL remains the primary control for interactive coding tasks.

Ctrl+I
AgentRouter AI
English

How can I help?

Ask me about configuration, installation, or specific features.