Claude Code CLI Setup

    Create a Gate.AI API Key

    1. Open gate.aiDashboard → API Keys, create and copy a key starting with sk-v1-…
    2. Confirm your account has sufficient balance

    Network connectivity check

    Replace GATEAI_API_KEY with your key:

    bash
    1export GATEAI_API_KEY="sk-v1-xxxxxxxxxxxxxxxx"

    Anthropic-compatible endpoint (Claude Code):

    bash
    1curl -s -o /dev/null -w "%{http_code}" \2  -H "x-api-key: $GATEAI_API_KEY" \3  -H "content-type: application/json" \4  -H "anthropic-version: 2023-06-01" \5  -d '{"model":"anthropic/claude-sonnet-4.6","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}' \6  https://api.gate.ai/anthropic/v1/messages
    • Returns 200: gateway is reachable; proceed with install and configuration
    • Returns 401: invalid or expired key — check the dashboard
    • Connection timeout: check local network or DNS; do not use https://api.gate.ai/v1

    Install Claude Code CLI

    macOS / Linux / WSL (recommended):

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

    Or with npm:

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

    If npm install fails

    This is usually caused by registry.npmjs.org timeouts or instability — unrelated to the Gate.AI gateway. Try one of the following:

    Option A: one-off install with a mirror (try first)

    bash
    1npm install -g @openai/codex --registry=https://registry.npmmirror.com2npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com

    Option B: set mirror globally

    bash
    1# Use npmmirror (common in China)2npm config set registry https://registry.npmmirror.com34# Verify registry5npm config get registry67# Reinstall8npm install -g @openai/codex9npm install -g @anthropic-ai/claude-code

    Option C: current shell session only

    bash
    1export NPM_CONFIG_REGISTRY=https://registry.npmmirror.com2npm install -g @openai/codex
    SymptomFix
    ETIMEDOUT / ECONNRESETSwitch mirror (Option A or B) and retry
    EACCES permission errorConfigure npm global prefix: mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global, and add export PATH=~/.npm-global/bin:$PATH to ~/.zshrc
    command not found: claude / codexInstalled but PATH not updated: restart the terminal, or confirm bin under npm config get prefix is on PATH

    Configure model

    Replace all sk-v1-your-key placeholders with your real key. No need to repeat unless you change the key or model.

    bash
    1mkdir -p ~/.claude23cat > ~/.claude/settings.json <<'EOF'4{5  "env": {6    "ANTHROPIC_BASE_URL": "https://api.gate.ai/anthropic",7    "ANTHROPIC_API_KEY": "sk-v1-your-key",8    "ANTHROPIC_MODEL": "anthropic/claude-sonnet-4.6"9  },10  "includeCoAuthoredBy": false11}12EOF1314# Clear old Anthropic / proxy sessions to avoid auth conflicts15claude /logout 2>/dev/null || true16unset ANTHROPIC_AUTH_TOKEN

    Store credentials only in settings.json. If ~/.zshrc still has ANTHROPIC_AUTH_TOKEN or a duplicate ANTHROPIC_API_KEY, comment or remove them.

    Verify setup

    In your project directory, start the CLI for AI-assisted coding in the terminal.

    Run claude

    bash
    1claude

    First check: run /status and confirm Base URL is https://api.gate.ai/anthropic and auth token is ANTHROPIC_API_KEY.

    Advanced configuration

    Auth conflict

    If you see Auth conflict: Both a token (ANTHROPIC_AUTH_TOKEN) and an API key (ANTHROPIC_API_KEY) are set:

    ScenarioFix
    Previously logged in via Anthropic OAuth / local proxyRun claude /logout, then start claude again
    Both token and key configured in shell and settingsKeep only ANTHROPIC_API_KEY; comment out ANTHROPIC_AUTH_TOKEN in ~/.zshrc

    Alternative configuration

    Shell environment variables (do not duplicate settings.json):

    bash
    1export ANTHROPIC_BASE_URL="https://api.gate.ai/anthropic"2export ANTHROPIC_API_KEY="sk-v1-xxxxxxxxxxxxxxxx"3export ANTHROPIC_MODEL="anthropic/claude-sonnet-4.6"

    Project-level settings (share structure; never commit real keys):

    PathPurpose
    .claude/settings.jsonProject-level, committable (no secrets)
    .claude/settings.local.jsonLocal project key; add to .gitignore

    Model environment variables

    Add to the env block in settings.json:

    VariablePurposeExample
    ANTHROPIC_DEFAULT_SONNET_MODELSonnet-tier tasksanthropic/claude-sonnet-4.6
    ANTHROPIC_DEFAULT_OPUS_MODELOpus-tier tasksanthropic/claude-opus-4.6
    ANTHROPIC_DEFAULT_HAIKU_MODELHaiku-tier tasksanthropic/claude-haiku-4.5
    CLAUDE_CODE_SUBAGENT_MODELSub-agent tasksanthropic/claude-sonnet-4.6

    Full list: model catalog. If auto fails, use an explicit model ID.

    Restore direct Anthropic (optional)

    bash
    1env -u ANTHROPIC_BASE_URL -u ANTHROPIC_API_KEY claude

    Troubleshooting

    Common Base URL mistakes

    bash
    1# ❌ Wrong (missing /anthropic prefix, 404)2https://api.gate.ai/v13https://api.gate.ai/v1/chat/completions45# ❌ Wrong (do not use full API path in Claude config)6https://api.gate.ai/anthropic/v1/messages7https://api.gate.ai/anthropic/messages89# ✅ Correct10https://api.gate.ai/anthropic/v111https://api.gate.ai/anthropic          # Claude Code CLI12https://api.gate.ai/anthropic/v1/messages  # curl key check (Anthropic)13https://api.gate.ai/openai/v1/responses    # curl key check (Codex)
    • /openai/v1/chat/completions works, but Codex must use the Responses API. On 404 for /responses, check wire_api = "responses", not the URL.
    • /openai/v1/models does not validate keys (invalid keys may still return 200). Use the curl endpoints above to verify keys.

    Quick reference

    SymptomTypeSuggestion
    Auth conflict warningAuth conflictRun claude /logout; keep only ANTHROPIC_API_KEY; remove or comment ANTHROPIC_AUTH_TOKEN
    401 / auth failureAuth errorCheck the key is correct and not expired
    404 on URLPath errorClaude → https://api.gate.ai/anthropic; Codex → https://api.gate.ai/openai/v1. Do not use https://api.gate.ai/v1/...
    Model not foundModel ID errorUse provider/model-name format (e.g. anthropic/claude-sonnet-4.6, openai/gpt-5.2); see the model catalog
    Still connecting to official domainConfig not appliedUse user-level config: Claude → ~/.claude/settings.json; Codex → ~/.codex/config.toml (project .codex/config.toml cannot override gateway settings)
    Shows offlineCLI behaviorDoes not affect main chat; safe to ignore
    402 / 429Quota / rate limitTop up or check key budget and rate limits
    npm install failsNetwork / permissionsSee "If npm install fails"