Gate.AIBlogHow to Set Up Claude Code with Gate.AI

    How to Set Up Claude Code with Gate.AI

    Guides

    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.

    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:

    1. Open Gate.AI.
    2. Go to Dashboard → API Keys.
    3. Create a new API key.
    4. Copy the key that starts with sk-or-v1-.
    5. 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:

    1. export GATEAI_API_KEY="YOUR_GATEAI_API_KEY"
    2. curl -s -o /dev/null -w "%{http_code}" \
    3. -H "x-api-key: $GATEAI_API_KEY" \
    4. -H "content-type: application/json" \
    5. -H "anthropic-version: 2023-06-01" \
    6. -d '{"model":"anthropic/claude-sonnet-4.6","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}' \
    7. 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:

    1. curl -fsSL https://claude.ai/install.sh | bash

    Alternative npm install:

    1. npm install -g @anthropic-ai/claude-code

    After installation, verify that the command is available:

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

    1. mkdir -p ~/.claude
    2. cat > ~/.claude/settings.json <<'EOF'
    3. {
    4. "env": {
    5. "ANTHROPIC_BASE_URL": "https://api.gate.ai/anthropic",
    6. "ANTHROPIC_API_KEY": "YOUR_GATEAI_API_KEY",
    7. "ANTHROPIC_MODEL": "anthropic/claude-sonnet-4.6"
    8. },
    9. "includeCoAuthoredBy": false
    10. }
    11. EOF

    Then clear old Anthropic or proxy sessions that may conflict with the Gate.AI API key:

    1. claude /logout 2>/dev/null || true
    2. unset 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:

    1. cd YOUR_PROJECT_DIRECTORY
    2. claude

    After Claude Code starts, run:

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

    1. 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_TOKEN and ANTHROPIC_API_KEY are both active.
      • Fix: Run claude /logout, unset ANTHROPIC_AUTH_TOKEN, and keep only ANTHROPIC_API_KEY.
    • Symptom: Claude Code returns 401 or 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 ETIMEDOUT or ECONNRESET.
      • Cause: The npm registry connection is unstable and unrelated to the Gate.AI gateway.
      • Fix: Retry with a mirror:
    1. 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.

    The content herein does not constitute any offer, solicitation, or recommendation. You should always seek independent professional advice before making any investment decisions. Please note that Gate may restrict or prohibit the use of all or a portion of the Services from Restricted Locations. For more information, please read the User Agreement