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.
- Official Claude Code site: https://www.anthropic.com/claude-code
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:
| Variable | Value |
|---|---|
ANTHROPIC_BASE_URL | https://ai.sammier.com |
ANTHROPIC_AUTH_TOKEN | Your 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-....
Node.js (recommended)
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 --versionInstall Claude Code
Install via the official script:
curl -fsSL https://claude.ai/install.sh | bashIf claude isn't found afterward, add the install directory to your PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrcVerify the install:
claude --versionOn Windows, install Claude Code via npm in PowerShell:
npm install -g @anthropic-ai/claude-codeWindows notes
-
PowerShell is recommended over CMD.
-
If you hit permission errors, try running the terminal as Administrator.
-
If prompted that
~/.local/binis not on yourPATH, add it:[Environment]::SetEnvironmentVariable('Path', ([Environment]::GetEnvironmentVariable('Path','User') + ";$HOME\.local\bin"), 'User')
Verify the install:
claude --versionPoint 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 keyTo make the change permanent, append those two export lines to your shell profile
(~/.bashrc or ~/.zshrc), then reload it:
source ~/.bashrc # or: source ~/.zshrcSet the variables for the current session:
$env:ANTHROPIC_BASE_URL = "https://ai.sammier.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-..." # your Code Router API keyTo 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
claudeTo choose a model from inside the session:
/modelPick 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 installedThen 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
AstrBot - Agent Chatbot
AstrBot Configuration Tutorial — Integrating the open-source Agent chatbot platform with Code Router to inject AI capabilities into instant messaging platforms like QQ, Feishu, DingTalk, and WeChat Work.
OpenAI Codex CLI
Configure OpenAI Codex CLI on Windows, macOS, and Linux to use Code Router as an OpenAI-compatible endpoint with a single API key and base URL.