For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Claude Code
Configure Claude Code CLI to use agentgateway
Configure Claude Code, the AI coding CLI by Anthropic, to route LLM requests through your agentgateway proxy.
The primary use case is routing Claude Code to non-Anthropic LLM backends (such as vLLM, Ollama, or any OpenAI-compatible provider) for cost optimization and flexibility. You can also configure direct routing to Anthropic or use a Claude Teams account as alternative options.
Before you begin
- Install the
agentgatewaybinary. - Install the Claude Code CLI (
npm install -g @anthropic-ai/claude-code).
The CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS environment variable disables Claude Code’s experimental beta features. You typically do not need this variable when proxying to non-Anthropic backends or standard Anthropic routing.
Only set this variable if you encounter errors like Extra inputs are not permitted when using advanced Anthropic features (such as experimental translation or extended thinking). If you use a non-Anthropic backend, this variable can be safely omitted.
Configure agentgateway with OpenAI-compatible backend
Route Claude Code to any OpenAI-compatible LLM provider (such as vLLM, Ollama, or local language models). This is the recommended approach for cost-effective and flexible deployment.
Create a configuration file with an OpenAI-compatible provider. The wildcard
*model name accepts any model. Claude Code sends the model in each request, so you do not need to pin a specific model.cat > config.yaml << 'EOF' # yaml-language-server: $schema=https://agentgateway.dev/schema/config llm: models: - name: "*" provider: openAI params: baseURL: "http://localhost:8000/v1" # vLLM or similar OpenAI-compatible endpoint apiKey: "mock-key" # Not used for local providers, but required by config EOFReplace
http://localhost:8000/v1with your OpenAI-compatible provider’s endpoint.Start agentgateway.
agentgateway -f config.yamlConfigure Claude Code to point to your agentgateway instance.
export ANTHROPIC_BASE_URL="http://localhost:4000"Verify the connection.
claude -p "Hello"
Configure agentgateway with Anthropic backend
Alternatively, route Claude Code directly to Anthropic’s API through agentgateway. This is useful if you want to leverage Anthropic’s latest models or features directly.
Get an Anthropic API key from the Anthropic Console.
Export your Anthropic API key.
export ANTHROPIC_API_KEY="sk-ant-your-key-here"Create a configuration file with the Anthropic provider. The wildcard
*model name accepts any model. Claude Code sends the model in each request, so you do not need to pin a specific model.cat > config.yaml << 'EOF' # yaml-language-server: $schema=https://agentgateway.dev/schema/config llm: models: - name: "*" provider: anthropic params: apiKey: "$ANTHROPIC_API_KEY" EOFStart agentgateway.
agentgateway -f config.yamlConfigure Claude Code.
export ANTHROPIC_BASE_URL="http://localhost:4000"Verify the connection.
claude -p "Hello"Example output:
Hello! How can I help you today?If you see an error like
API Error: 400 context_management: Extra inputs are not permitted, Claude Code is sending experimental beta parameters that agentgateway does not yet support. Disable experimental betas and retry the request.export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 claude -p "Hello"
Claude Teams or Pro account
If you have a Claude Teams or Pro account, you can use agentgateway for request routing without an API key. Authentication is handled by your Claude subscription via OAuth.
Create a configuration file. Agentgateway listens on port
4001and exposes Claude at the/claudepath.cat > config.yaml << 'EOF' binds: - port: 4001 listeners: - name: default protocol: HTTP routes: - name: claude-agent matches: - path: pathPrefix: /claude policies: urlRewrite: path: prefix: / backends: - ai: name: claude-agent provider: anthropic: {} policies: ai: routes: /v1/messages: messages /v1/messages/count_tokens: anthropicTokenCount '*': passthrough EOFStart agentgateway.
agentgateway -f config.yamlSet the
ANTHROPIC_BASE_URLenvironment variable to point Claude Code at the/claudepath.export ANTHROPIC_BASE_URL="http://localhost:4001/claude"Verify the connection.
claude -p "Hello"