---
title: "Claude Code via Gateway"
description: "Point Claude Code at AI Gateway's Anthropic-compatible endpoint, keep its credential outside the project, and give the agent a dedicated key and budget."
canonical_url: "https://vercel.com/academy/ai-gateway/claude-code-with-gateway"
md_url: "https://vercel.com/academy/ai-gateway/claude-code-with-gateway.md"
docset_id: "vercel-academy"
doc_version: "1.0"
last_updated: "2026-08-08T23:27:13.520Z"
content_type: "lesson"
course: "ai-gateway"
course_title: "Using AI Gateway in Production"
prerequisites:  []
---

<agent-instructions>
Vercel Academy — structured learning, not reference docs.
Lessons are sequenced.
Adapt commands to the human's actual environment (OS, package manager, shell, editor) — detect from project context or ask, don't assume.
The lesson shows one path; if the human's project diverges, adapt concepts to their setup.
Preserve the learning goal over literal steps.
Quizzes are pedagogical — engage, don't spoil.
Quiz answers are included for your reference.
</agent-instructions>

# Claude Code via Gateway

# 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.

\*\*Note: Quick Answer\*\*

Set `ANTHROPIC_BASE_URL` to `https://ai-gateway.vercel.sh`, pass a Gateway key through `ANTHROPIC_AUTH_TOKEN`, and leave `ANTHROPIC_API_KEY` empty. Start Claude Code from that environment and use a dedicated Gateway key with its own budget.

## Outcome

Run a harmless Claude Code task through the Gateway configuration without exposing the credential in the project.

## Fast Track

1. Create a dedicated, budgeted Gateway key for Claude Code
2. Configure the three environment variables below
3. 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:

```bash filename="shell configuration"
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:

```text
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.

\*\*Note: Using Bedrock or Vertex\*\*

When Claude Code routes through Bedrock or Vertex, set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`. This prevents Anthropic-specific beta headers from causing errors on those providers.

## 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

- [How do I run OpenCode through the Gateway?](/ai-gateway/stay-aware/opencode-with-gateway)
- [How do I run Codex through the Gateway?](/ai-gateway/stay-aware/codex-with-gateway)
- [How do I set a budget?](/ai-gateway/save-money/set-a-budget)


---

[Full course index](/academy/llms.txt) · [Sitemap](/academy/sitemap.md)
