How Do I Run Claude Code Through the Gateway?
Claude Code can use AI Gateway without changing the way you work in the terminal. The connection lives in environment variables, outside the repository.
Outcome
Run a harmless Claude Code task through the Gateway configuration without exposing the credential in the project.
Fast Track
- Create a dedicated, budgeted Gateway key for Claude Code
- Configure the three environment variables below
- Start Claude Code and run a small read-only task
Hands-on exercise
Use a throwaway repository with a small file such as demo.ts. Configure the environment before starting Claude Code:
export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh"
export ANTHROPIC_AUTH_TOKEN="$AI_GATEWAY_API_KEY"
export ANTHROPIC_API_KEY=""ANTHROPIC_AUTH_TOKEN carries the Gateway key. Leaving ANTHROPIC_API_KEY empty prevents Claude Code from selecting that credential path instead.
Keep the real token out of shell screenshots, recordings, and source control. A prepared example with [redacted] is safer than opening a live shell profile.
Try It
Start Claude Code in the throwaway repository and ask:
Explain demo.ts in three bullets. Do not modify anything.Claude Code should answer normally. If it does not connect, confirm that the process inherited all three variables from the shell that launched it.
Done-When
- Claude Code completes the read-only task
- The Gateway key does not appear in the repository or terminal output
- Claude Code uses a dedicated key with an intentional budget
- You know where the environment configuration is applied
Solution
The complete integration is the three-variable shell configuration above. The repository stays unchanged, and the credential remains in the environment that starts Claude Code.
Related Questions
Was this helpful?