How to Set Up Claude Code with Gate.AI
Gate.AI Claude Code CLI Gateway Setup
Gate.AI can connect Claude Code CLI to an Anthropic-compatible gateway so developers can run terminal-based AI coding workflows with a Gate.AI API key and a supported Claude model ID. This matters when a developer wants Claude Code to route requests through Gate.AI instead of using a direct Anthropic-only setup. This guide covers the Gate.AI Claude Code CLI setup, endpoint verification, model configuration, and troubleshooting; it does not cover Claude Desktop, Cursor, or Codex configuration.
Source basis: Gate.AI official documentation and Claude Code documentation, as of June 2026.
Prerequisites
- A Gate.AI account with an API key and sufficient balance.
- Claude Code CLI access on macOS, Linux, or WSL.
What Will You Be Able to Do After This Guide?
After completing this gate.ai claude code setup, you will be able to start Claude Code from a project directory and send Claude Code requests through https://api.gate.ai/anthropic.
This guide covers the recommended user-level settings.json configuration, a direct endpoint test, and common fixes for 401, 404, auth conflict, timeout, and npm installation issues.
- For broader API gateway setup, use the related Gate.AI API integration guide.
- For IDE-based setup, use the related Gate.AI Cursor setup guide.
Step 1: Create a Gate.AI API Key
Create a Gate.AI key first because Claude Code needs the key before the Base URL and model configuration can work.
Action:
- Open Gate.AI.
- Go to Dashboard → API Keys.
- Create a new API key.
- Copy the key that starts with
sk-or-v1-. - Confirm that the account has sufficient balance.
Do not paste the real key into a public repository, issue tracker, shared screenshot, or committed project file.
Step 2: Check Gateway Connectivity
Test the Anthropic-compatible endpoint before installing or configuring Claude Code so that key or network issues are separated from CLI configuration issues.
Replace YOUR_GATEAI_API_KEY with your real Gate.AI key:
export GATEAI_API_KEY="YOUR_GATEAI_API_KEY"curl -s -o /dev/null -w "%{http_code}" \-H "x-api-key: $GATEAI_API_KEY" \-H "content-type: application/json" \-H "anthropic-version: 2023-06-01" \-d '{"model":"anthropic/claude-sonnet-4.6","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}' \https://api.gate.ai/anthropic/v1/messages
You should see one of these results:
| Result | Meaning | Next action |
|---|---|---|
| 200 | Gate.AI gateway is reachable | Continue to Claude Code installation |
| 401 | API key is invalid, expired, or copied incorrectly | Check the Gate.AI dashboard key |
| Timeout | Local network, DNS, or firewall issue | Check network access and retry |
| 404 | Wrong path or Base URL pattern | Use the Anthropic path shown above |
The key point is that Claude Code uses the Anthropic-compatible Gate.AI route, not the generic https://api.gate.ai/v1 path.
Step 3: Install Claude Code CLI
Install Claude Code CLI after the Gate.AI endpoint check passes so the remaining work is limited to local CLI setup.
Recommended install for macOS, Linux, or WSL:
curl -fsSL https://claude.ai/install.sh | bash
Alternative npm install:
npm install -g @anthropic-ai/claude-code
After installation, verify that the command is available:
claude --version
If the terminal says command not found: claude, restart the terminal and confirm that the installation directory is on your PATH.
Step 4: Configure Claude Code Settings
Configure Claude Code with Gate.AI’s Anthropic Base URL, API key, and model ID in ~/.claude/settings.json.
Use user-level settings when one Gate.AI Claude Code setup should apply across all projects:
mkdir -p ~/.claudecat > ~/.claude/settings.json <<'EOF'{"env": {"ANTHROPIC_BASE_URL": "https://api.gate.ai/anthropic","ANTHROPIC_API_KEY": "YOUR_GATEAI_API_KEY","ANTHROPIC_MODEL": "anthropic/claude-sonnet-4.6"},"includeCoAuthoredBy": false}EOF
Then clear old Anthropic or proxy sessions that may conflict with the Gate.AI API key:
claude /logout 2>/dev/null || trueunset ANTHROPIC_AUTH_TOKEN
Store credentials in one place. If ~/.zshrc, ~/.bashrc, or another shell profile still contains ANTHROPIC_AUTH_TOKEN or a duplicate ANTHROPIC_API_KEY, comment out the duplicate entry and open a new terminal.
Step 5: Verify Claude Code in a Project
Start Claude Code from the project directory where you want AI-assisted coding.
Run:
cd YOUR_PROJECT_DIRECTORYclaude
After Claude Code starts, run:
Plain / status
You should confirm that the Base URL is https://api.gate.ai/anthropic and the auth method is based on ANTHROPIC_API_KEY. Then send a small test prompt such as:
In one sentence, describe this repository.
A normal response without auth, routing, or model errors means Claude Code is sending requests through Gate.AI.
What Does the Correct Configuration Look Like?
Use this table as a quick reference when checking a gate.ai claude code setup.
| Item | Correct value | Notes |
|---|---|---|
| Claude Code Base URL | https://api.gate.ai/anthropic | Use this in Claude Code settings |
| Curl key-check URL | https://api.gate.ai/anthropic/v1/messages | Use this only for endpoint verification |
| API key variable | ANTHROPIC_API_KEY | Claude Code sends this as an API key |
| Model variable | ANTHROPIC_MODEL | Example: anthropic/claude-sonnet-4.6 |
| Model ID format | provider/model-name | Do not use a built-in alias if Gate.AI requires a full model ID |
The most common mistake is mixing Claude Code configuration URLs with raw API request URLs. Claude Code should use the Base URL, while curl verification should use the full /v1/messages endpoint.
Which Base URLs Should You Avoid?
Incorrect Base URLs usually produce 404 errors or route requests to the wrong protocol.
| Use case | Correct value | Common wrong value |
|---|---|---|
| Claude Code CLI Base URL | https://api.gate.ai/anthropic | https://api.gate.ai/v1 |
| Anthropic curl key check | https://api.gate.ai/anthropic/v1/messages | https://api.gate.ai/anthropic/messages |
| OpenAI-compatible tools | https://api.gate.ai/openai/v1 | https://api.gate.ai/v1/chat/completions |
| Claude Code settings | https://api.gate.ai/anthropic | https://api.gate.ai/anthropic/v1/messages |
Use the Anthropic path for Claude Code and the OpenAI path only for OpenAI-compatible tools.
Why Is Claude Code Not Working? Troubleshooting Checklist
- Symptom: Claude Code shows
Auth conflict: Both a token and an API key are set.- Cause:
ANTHROPIC_AUTH_TOKENandANTHROPIC_API_KEYare both active. - Fix: Run
claude /logout, unsetANTHROPIC_AUTH_TOKEN, and keep onlyANTHROPIC_API_KEY.
- Cause:
- Symptom: Claude Code returns
401or an auth failure.- Cause: The Gate.AI key is wrong, expired, not exported, or overwritten by another shell setting.
- Fix: Recopy the key from Dashboard → API Keys and confirm the active value with
echo $ANTHROPIC_API_KEY.
- Symptom: Claude Code returns
404.- Cause: The Base URL is using the OpenAI route or a full request path.
- Fix: Set Claude Code to
https://api.gate.ai/anthropic, not/openai/v1,/v1, or/anthropic/v1/messages.
- Symptom: The endpoint test times out.
- Cause: Local network, DNS, proxy, or firewall access is blocking the request.
- Fix: Test a different network, check DNS, and retry the curl command before changing Claude Code settings.
- Symptom: npm installation fails with
ETIMEDOUTorECONNRESET.- Cause: The npm registry connection is unstable and unrelated to the Gate.AI gateway.
- Fix: Retry with a mirror:
npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com
If permission errors appear during npm installation, configure a user-level npm prefix instead of using unsafe elevated installs.
What Can You Configure or Build Next?
After the Gate.AI Claude Code setup works, configure related developer workflows:
- Use the Gate.AI API integration guide to connect OpenAI-compatible SDKs and standard API workflows.
- Use the Gate.AI Cursor setup guide if your team also wants Gate.AI models inside Cursor.
- Add explicit model IDs for Sonnet, Opus, or Haiku tiers only after checking the current Gate.AI model catalog.
FAQs
Can I use https://api.gate.ai/openai/v1 for Claude Code?
No. Claude Code should use the Anthropic-compatible Gate.AI Base URL: https://api.gate.ai/anthropic. The OpenAI-compatible path is for OpenAI-style tools, SDKs, and endpoints.
Why does /models return 200 but Claude Code still fails?
A model-list endpoint may not prove that the active key works for Claude Code. Use the Anthropic-compatible /anthropic/v1/messages curl check because the test sends an authenticated message request.
Should I store the Gate.AI API key in shell variables or settings.json?
Use one method and avoid duplicates. For a stable local setup, user-level ~/.claude/settings.json is easier to audit. For temporary sessions, shell variables are acceptable.
Can I set the model to auto in Claude Code?
Use an explicit Gate.AI model ID first, such as anthropic/claude-sonnet-4.6. If Gate.AI auto routing is enabled and supported for your setup, you can test auto; switch back to an explicit model ID if routing errors appear.