Claude Code and Claude Agent SDK
LLM Router provides a fully compatible Anthropic endpoint (/v1), meaning you can point Claude Code and the Claude Agent SDK directly to your gateway.
By routing Claude Code through LLM Router, you instantly unlock:
- Cost Savings: Automatic context compression on long, token-heavy terminal sessions.
- Security: Enterprise PII redaction (masking API keys and passwords in your local
.envfiles from being sent to Anthropic). - Resilience: Automatic failover to other providers (like Amazon Bedrock or Google Vertex AI) if the primary Anthropic API goes down.
Provider Fallback Note: If you configure LLM Router to fall back from
Anthropic to Amazon Bedrock or Vertex AI, be aware that Claude Code
automatically injects Anthropic-specific beta headers. To prevent errors
during fallback, set
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 in your
environment.Configuring Claude Code (CLI)
Claude Code is Anthropic’s agentic coding tool that runs in your terminal. You can easily configure it to send all traffic through LLM Router.1. Clear Existing Auth
First, log out if you are already logged into the default Anthropic service:2. Configure Environment Variables
To point Claude Code to LLM Router, add the following variables to your shell configuration file (e.g.,~/.zshrc or ~/.bashrc):
3. Run Claude Code
Reload your terminal (e.g.,source ~/.zshrc) and start Claude Code:
(Optional) macOS: Secure Token Storage
If you are on a Mac and prefer to manage your LLM Router API key through Keychain for better local security, run this command:~/.zshrc export to read from the Keychain:
With the Claude Agent SDK
The Claude Agent SDK (@anthropic-ai/claude-agent-sdk) lets you build custom AI agents using the same core loop that powers Claude Code.
You can route these custom SDK requests through LLM Router by overriding the env option in your query:
agent.ts