Thanks to visit codestin.com
Credit goes to vercel.com

Menu

Claude Code

Last updated January 29, 2026

AI Gateway provides Anthropic-compatible API endpoints so you can use Claude Code through a unified gateway.

Claude Code is Anthropic's agentic coding tool. You can configure it to use Vercel AI Gateway, enabling you to:

  • Monitor traffic and token usage in your AI Gateway Overview
  • View detailed traces in Vercel Observability under AI
  1. First, log out if you're already logged in:

    claude /logout

    Next, ensure you have your AI Gateway API key handy, and configure Claude Code to use the AI Gateway by adding this to your shell configuration file, for example in ~/.zshrc or ~/.bashrc:

    export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh"
    export ANTHROPIC_AUTH_TOKEN="your-ai-gateway-api-key"
    export ANTHROPIC_API_KEY=""

    Setting ANTHROPIC_API_KEY to an empty string is important. Claude Code checks this variable first, and if it's set to a non-empty value, it will use that instead of ANTHROPIC_AUTH_TOKEN.

  2. Run claude to start Claude Code with AI Gateway:

    claude

    Your requests will now be routed through Vercel AI Gateway.

  3. If you're on a Mac and would like to manage your API key through a keychain for improved security, set your API key in the keystore with:

    security add-generic-password -a "$USER" -s "ANTHROPIC_AUTH_TOKEN" \
      -w "your-ai-gateway-api-key"

    and edit the ANTHROPIC_AUTH_TOKEN line above to:

    export ANTHROPIC_AUTH_TOKEN=$(
      security find-generic-password -a "$USER" -s "ANTHROPIC_AUTH_TOKEN" -w
    )

    If you need to update the API key value later, you can do it with:

    security add-generic-password -U -a "$USER" -s "ANTHROPIC_AUTH_TOKEN" \
      -w "new-ai-gateway-api-key"

If you have a Claude Code Max subscription, you can use your subscription through the AI Gateway. This allows you to leverage your existing Claude subscription while still benefiting from the gateway's observability, monitoring, and routing features.

  1. Add the following to your shell configuration file (e.g., ~/.zshrc or ~/.bashrc):

    export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh"
    export ANTHROPIC_CUSTOM_HEADERS="x-ai-gateway-api-key: Bearer your-ai-gateway-api-key"

    Replace your-ai-gateway-api-key with your actual AI Gateway API key.

  2. Start Claude Code:

    claude
  3. If you're not already logged in, Claude Code will prompt you to authenticate. Choose Option 1 - Claude account with subscription and log in as normal with your Anthropic account.

    If you encounter issues, try logging out with claude /logout and logging in again.

Your requests will now be routed through Vercel AI Gateway using your Claude Code Max subscription. You'll be able to monitor usage and view traces in your Vercel dashboard while using your Anthropic subscription for model access.


Was this helpful?

supported.