Code RouterCode Router
User GuideAPI ReferenceAI ApplicationsHelp & SupportBusiness Cooperation

Claude Code

Configure Claude Code, Anthropic's terminal coding agent, to route requests through Code Router using an Anthropic-compatible base URL and your Code Router API key.

What is Claude Code?

Claude Code is Anthropic's terminal-based coding agent. It reads and edits files across a project, runs commands, and works directly from your shell.

Because Claude Code honors standard Anthropic-compatible environment variables, you can point it at Code Router instead of Anthropic's default endpoint. Code Router then forwards your requests to whichever upstream model provider is configured behind your key.

How it works

Code Router exposes an OpenAI-compatible gateway (and an Anthropic-compatible surface for tools like Claude Code). You get one API key and one base URL; Code Router resolves the requested model to an upstream provider and tracks usage against your key.

To make Claude Code use Code Router, you set two environment variables before launching it:

VariableValue
ANTHROPIC_BASE_URLhttps://ai.sammier.com
ANTHROPIC_AUTH_TOKENYour Code Router API key (looks like sk-...)

Where do these values come from?

  • The base URL above is a demo placeholder. Use the base URL of the Code Router deployment you actually connect to.
  • The API key is the key you create in your Code Router account. Treat it like a password.
  • Which underlying models are available, and any usage limits, depend on your Code Router deployment's configuration. (Available model list and limits: TBD / 待补)

Prerequisites

A Code Router API key

Create a key in your Code Router account and copy it. It will look like sk-....

Claude Code runs on Node.js. Install the current LTS release from https://nodejs.org/ if you don't already have it. Verify with:

node --version
npm --version

Install Claude Code

Install via the official script:

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

If claude isn't found afterward, add the install directory to your PATH:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc

Verify the install:

claude --version

On Windows, install Claude Code via npm in PowerShell:

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

Windows notes

  • PowerShell is recommended over CMD.

  • If you hit permission errors, try running the terminal as Administrator.

  • If prompted that ~/.local/bin is not on your PATH, add it:

    [Environment]::SetEnvironmentVariable('Path', ([Environment]::GetEnvironmentVariable('Path','User') + ";$HOME\.local\bin"), 'User')

Verify the install:

claude --version

Point Claude Code at Code Router

Set the two environment variables, then launch claude.

Set the variables for your current shell session:

export ANTHROPIC_BASE_URL="https://ai.sammier.com"
export ANTHROPIC_AUTH_TOKEN="sk-..."   # your Code Router API key

To make the change permanent, append those two export lines to your shell profile (~/.bashrc or ~/.zshrc), then reload it:

source ~/.bashrc   # or: source ~/.zshrc

Set the variables for the current session:

$env:ANTHROPIC_BASE_URL = "https://ai.sammier.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-..."   # your Code Router API key

To persist them across sessions:

[Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://ai.sammier.com', 'User')
[Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-...', 'User')

Close and reopen PowerShell so the persisted values take effect.

This redirects all requests

Once ANTHROPIC_BASE_URL points at Code Router, Claude Code sends all model traffic through Code Router rather than Anthropic's default endpoint. Usage is billed/accounted against your Code Router key, not an Anthropic subscription.

Run it

# Launch in the current directory
claude

# Or open a specific project
cd /path/to/your/project
claude

To choose a model from inside the session:

/model

Pick from the models your Code Router deployment exposes. The exact model names and which ones are available depend on your deployment's configuration (model list: TBD / 待补).

Verify the connection

A quick way to confirm Claude Code is talking to Code Router:

echo $ANTHROPIC_BASE_URL   # should print your Code Router base URL
claude --version           # confirms the CLI is installed

Then start claude and send a short prompt. If you get a normal response, routing is working.

You can also sanity-check the gateway directly with curl against the OpenAI-compatible endpoint:

curl https://ai.sammier.com/v1/models \
  -H "Authorization: Bearer sk-..."

Troubleshooting

Feedback

Found a problem with these instructions or with Code Router itself? Open an issue on the source repository: github.com/ssgzy/Router-new-api.

How is this guide?

Last updated on