Using Routic with Claude Code

Route Claude Code CLI through Routic's Anthropic-compatible endpoint to use Claude models at a lower cost.

How it works

Routic supports both OpenAI-compatible and Anthropic-compatible message formats. Claude Code uses Anthropic's /v1/messages API path by default. Routic proxies this path and routes to the appropriate backend model.

Prerequisites

  • Claude Code CLI installed (npm install -g @anthropic-ai/claude-code)
  • A Routic Base URL and API Key

Option 1: Let your AI agent configure it (fastest)

Tell your AI agent:

Configure Claude Code to use Routic as the Anthropic API backend.

Give it this information:

Environment variables to set (add to ~/.bashrc, ~/.zshrc, or equivalent):

VariableValue
ANTHROPIC_BASE_URLhttps://api.routic.ai
ANTHROPIC_API_KEYYour Routic API Key (starts with sk-)

Set ANTHROPIC_BASE_URL to the host only — no trailing /v1. Claude Code appends the path automatically.

Or via config file ~/.claude/settings.json (merge, don't overwrite other entries):

{
  "api": {
    "baseURL": "https://api.routic.ai",
    "apiKey": "sk-YOUR_KEY_HERE"
  }
}

Once the agent is done, replace sk-YOUR_KEY_HERE with your actual key and restart your terminal.

Option 2: Manual setup

Environment variables (recommended)

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

export ANTHROPIC_BASE_URL="https://api.routic.ai"
export ANTHROPIC_API_KEY="sk-YOUR_KEY_HERE"

Then source ~/.zshrc (or restart your terminal) and use claude as normal.

Inline per command

ANTHROPIC_BASE_URL="https://api.routic.ai" \
ANTHROPIC_API_KEY="sk-YOUR_KEY_HERE" \
claude "Review this function for me"

Config file

Edit ~/.claude/settings.json (merge, don't overwrite other entries):

{
  "api": {
    "baseURL": "https://api.routic.ai",
    "apiKey": "sk-YOUR_KEY_HERE"
  }
}

Config format may change across versions. Check Claude Code docs for the latest.

Verify

claude "hello, reply with pong"

A normal response confirms success. A 401 or authentication_error means the API Key is wrong.

Specify a model

claude --model claude-3-5-sonnet-20241022 "your prompt"

Model names must match Routic's model catalog exactly.

Troubleshooting

invalid_api_key
The API Key is malformed or expired. Regenerate it from the console.

Still hitting Anthropic directly after setting ANTHROPIC_BASE_URL
Confirm the variable is exported: echo $ANTHROPIC_BASE_URL. You may need to restart the terminal.

Responses look wrong
The model name may not be in the Routic catalog. Check the model catalog.

Related