Skip to content
🎯 New workshop: Govern AI Costs in Real Time — Hands-On with agentgateway agentgateway has joined the Agentic AI FoundationLearn more

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Page as Markdown

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

  1. Install the agentgateway binary.
  2. Install the Claude Code CLI (npm install -g @anthropic-ai/claude-code).

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.

  1. 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
    EOF

    Replace http://localhost:8000/v1 with your OpenAI-compatible provider’s endpoint.

  2. Start agentgateway.

    agentgateway -f config.yaml
  3. Configure Claude Code to point to your agentgateway instance.

    export ANTHROPIC_BASE_URL="http://localhost:4000"
  4. 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.

  1. Get an Anthropic API key from the Anthropic Console.

  2. Export your Anthropic API key.

    export ANTHROPIC_API_KEY="sk-ant-your-key-here"
  3. 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"
    EOF
  4. Start agentgateway.

    agentgateway -f config.yaml
  5. Configure Claude Code.

    export ANTHROPIC_BASE_URL="http://localhost:4000"
  6. 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"
For pinned model configuration, extended thinking, and other options, see the Anthropic provider page.

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.

  1. Create a configuration file. Agentgateway listens on port 4001 and exposes Claude at the /claude path.

    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
    EOF
  2. Start agentgateway.

    agentgateway -f config.yaml
  3. Set the ANTHROPIC_BASE_URL environment variable to point Claude Code at the /claude path.

    export ANTHROPIC_BASE_URL="http://localhost:4001/claude"
  4. Verify the connection.

    claude -p "Hello"

Next steps

Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.