DEV Community

HopBase
HopBase

Posted on

Setting Up Custom ANTHROPIC_BASE_URL & OPENAI_BASE_URL for Teams in Claude Code, Codex CLI, and Antigravity CLI

Rolling out terminal coding agents across an engineering team looks trivial until five developers hit five different authentication and path bugs on day one.

One engineer sets ANTHROPIC_BASE_URL with a trailing /v1 and gets 404 on /v1/v1/messages. Another sets OPENAI_BASE_URL in .zshrc expecting OpenAI's Codex CLI to pick it up—only to discover Codex CLI ignores OPENAI_BASE_URL unless a [model_providers.*] block is declared in ~/.codex/config.toml with wire_api = "responses". A third installs Google's Antigravity CLI (agy), exports GEMINI_API_KEY, and still gets prompted for browser OAuth because ~/.gemini/antigravity-cli/settings.json is missing "modelProvider": "gemini".

Meanwhile, whoever holds the company card has a bigger problem: sharing a single raw vendor API key in Slack means zero per-developer spend caps, no attribution when an autonomous loop burns $300 overnight, and a painful laptop-by-laptop migration the day an engineer leaves.

This guide gives you exact, production-tested configuration files for running Claude Code, OpenAI Codex CLI, and Google Antigravity CLI (agy) against a unified enterprise gateway (https://api.hop-base.com), along with the base-URL path rules, config-precedence traps, per-developer quota controls, and key-rotation patterns that keep a team setup maintainable.


1. Base URL Suffix Matrix: Why Half of Custom Gateway Setups Return HTTP 404

Before touching any config file, lock down the exact path contract for each CLI. Different agent runtimes append different path prefixes internally:

Coding Agent / SDK Base URL Variable or Config Key Exact Value Path Appended by Client Auth Header Sent
Claude Code CLI ANTHROPIC_BASE_URL https://api.hop-base.com (no /v1) /v1/messages, /v1/messages/count_tokens x-api-key / Authorization: Bearer
OpenAI Codex CLI base_url in ~/.codex/config.toml https://api.hop-base.com/v1 (with /v1) /responses (wire_api = "responses") Authorization: Bearer
OpenAI Python / Node SDKs OPENAI_BASE_URL https://api.hop-base.com/v1 (with /v1) /chat/completions, /responses Authorization: Bearer
Antigravity CLI (agy) GOOGLE_GEMINI_BASE_URL https://api.hop-base.com (no /v1beta) /v1beta/models/{model}:streamGenerateContent?alt=sse x-goog-api-key

The golden rule: only OpenAI-compatible clients (OPENAI_BASE_URL and Codex CLI base_url) include /v1 in the Base URL. Both Claude Code (ANTHROPIC_BASE_URL) and Antigravity CLI (GOOGLE_GEMINI_BASE_URL) expect the bare origin and attach /v1/... or /v1beta/... themselves.

Always verify which model IDs a given developer key is authorized to call before launching any CLI:

curl -fsS https://api.hop-base.com/v1/models \
  -H "Authorization: Bearer $HOPBASE_API_KEY" | jq -r '.data[].id'
Enter fullscreen mode Exit fullscreen mode

2. Claude Code: ANTHROPIC_BASE_URL & the settings.json Precedence Trap

Claude Code speaks the native Anthropic Messages API (POST /v1/messages). You can configure it either via ~/.claude/settings.json or via shell environment variables—but you should never mix both on the same machine.

Option A: Declarative ~/.claude/settings.json (Recommended for Team Onboarding)

Writing the configuration into ~/.claude/settings.json works identically across macOS, Linux, Windows, and IDE-integrated terminals (VS Code, Cursor, JetBrains) that do not always source interactive .zshrc files:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.hop-base.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-dev-alice-key",
    "ANTHROPIC_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
  }
}
Enter fullscreen mode Exit fullscreen mode

Precedence Pitfall: Any variable present inside the "env" block of ~/.claude/settings.json overrides shell environment variables of the same name (export ANTHROPIC_AUTH_TOKEN=...). If a developer updates .zshrc later and wonders why Claude Code is still sending an old token, check ~/.claude/settings.json first.

Option B: Shell Environment + Secret Manager Injection (Recommended for Zero-Plaintext Laptops)

If your team injects secrets dynamically from 1Password CLI (op run), Doppler, AWS Vault, or direnv so keys never sit on disk in plaintext, keep ANTHROPIC_AUTH_TOKEN out of ~/.claude/settings.json and export it in your shell wrapper:

# ~/.zshrc or ~/.bashrc (macOS / Linux)
export ANTHROPIC_BASE_URL="https://api.hop-base.com"
export ANTHROPIC_AUTH_TOKEN="sk-dev-alice-key"

# Launch with an explicit flagship or daily-driver model
claude --model claude-opus-5-5
# Or switch mid-session inside Claude Code:
# /model claude-fable-5-2
Enter fullscreen mode Exit fullscreen mode

On Windows PowerShell:

setx ANTHROPIC_BASE_URL "https://api.hop-base.com"
setx ANTHROPIC_AUTH_TOKEN "sk-dev-alice-key"
# Reopen PowerShell, then run:
claude --model claude-sonnet-5-5
Enter fullscreen mode Exit fullscreen mode

Bonus: Running 1M-Context Non-Claude Models Natively in Claude Code

When your gateway exposes native Anthropic Messages (POST /v1/messages) for 1M-context models such as qwen4-max, kimi-k3.1-pro, or deepseek-v4.1-flash-1017, Claude Code connects directly without any local translation proxy. Just add CLAUDE_CODE_MAX_CONTEXT_TOKENS so Claude Code does not prematurely compact the session at its default 200K threshold:

export ANTHROPIC_BASE_URL="https://api.hop-base.com"
export ANTHROPIC_AUTH_TOKEN="sk-dev-alice-key"
export ANTHROPIC_MODEL="qwen4-max"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.8-flash"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1000000
claude
Enter fullscreen mode Exit fullscreen mode

Full walkthrough and one-click installer details: Claude Code Custom Base URL Guide.


3. OpenAI Codex CLI: Custom base_url & wire_api = "responses" in config.toml

Standard OpenAI SDK scripts honor OPENAI_BASE_URL=https://api.hop-base.com/v1 and OPENAI_API_KEY. OpenAI Codex CLI is stricter: it uses OpenAI's Responses API (POST /v1/responses) rather than legacy Chat Completions, and it requires an explicit custom provider table in ~/.codex/config.toml (or C:\Users\<your-name>\.codex\config.toml on Windows).

Copy-Paste ~/.codex/config.toml

model_provider = "hopbase"
model = "gpt-6.2-sol"
model_reasoning_effort = "high"

[model_providers.hopbase]
name = "HopBase"
base_url = "https://api.hop-base.com/v1"
wire_api = "responses"
env_key = "OPENAI_API_KEY"
Enter fullscreen mode Exit fullscreen mode

Then export the developer's scoped key (and optionally OPENAI_BASE_URL so other OpenAI-compatible CLI tools and Python/Node scripts in the same shell share the exact same gateway endpoint):

export OPENAI_BASE_URL="https://api.hop-base.com/v1"
export OPENAI_API_KEY="sk-dev-alice-codex-key"

codex
Enter fullscreen mode Exit fullscreen mode

Three Codex CLI Pitfalls to Avoid in Team Rollouts

  1. Never combine requires_openai_auth = true with env_key in the same provider block. Codex CLI has two mutually exclusive credential paths: env_key = "OPENAI_API_KEY" (environment variable) and requires_openai_auth = true (which reads ~/.codex/auth.json). Mixing both in Codex 0.153+ causes the client to omit the Authorization header completely, resulting in 401 missing_api_key.
  2. Right-size model_reasoning_effort. Accepted values are low, medium, high, and xhigh. Leaving every developer defaulted to xhigh on flagship models burns maximum reasoning tokens on trivial file renames; standardize your team template on medium or high and reserve xhigh for deep architectural debugging.
  3. Disable Codex web search if you want clean logs. Codex CLI's built-in web search calls /v1/alpha/search and remote compaction calls /v1/responses/compact. On standard OpenAI-compatible gateways those proprietary endpoints return 404 without harming normal coding turns, so turning web search off in Codex keeps logs noise-free.

Full setup reference: Codex CLI OpenAI-Compatible Base URL Guide.


4. Google Antigravity CLI (agy): Native Gemini Protocol via GOOGLE_GEMINI_BASE_URL

Google's terminal coding agent, Antigravity CLI (agy, version 1.1.13+, verified through 1.5.12), speaks the native Gemini streaming protocol (POST /v1beta/models/{model}:streamGenerateContent?alt=sse)—meaning tool calls, multi-file edits, --continue session resumption, and multimodal image inputs run without lossy OpenAI-to-Gemini schema translation.

Step 1: Switch agy from Google OAuth to API Key Mode

Create or edit ~/.gemini/antigravity-cli/settings.json:

{
  "modelProvider": "gemini"
}
Enter fullscreen mode Exit fullscreen mode

The value must be lowercase "gemini". If a developer skips this file and only exports environment variables, agy ignores the custom URL and opens a Google account sign-in flow.

Step 2: Export GOOGLE_GEMINI_BASE_URL and GEMINI_API_KEY

export GEMINI_API_KEY="sk-dev-alice-gemini-key"
export GOOGLE_GEMINI_BASE_URL="https://api.hop-base.com"

# Model names in agy append -low, -medium, or -high to set thinkingLevel:
agy --model gemini-4-argon-medium
# Single-shot non-interactive prompt:
agy -p "Audit database migration 0042 for lock contention" --model gemini-4-hydrogen-low
Enter fullscreen mode Exit fullscreen mode

Operational Notes for agy Administrators

  • Root URL only: Set GOOGLE_GEMINI_BASE_URL=https://api.hop-base.com with no /v1beta suffix. Also note that agy reads environment variables from the launching shell—it does not load project .env files or GOOGLE_API_KEY.
  • Background safety-review helper calls: After each agent step, agy automatically invokes gemini-3.1-flash-lite-preview or gemini-3.8-flash in the background. Make sure the developer's API key belongs to a group (such as HopBase's Gemini Official Direct (Enterprise) group) that serves both the primary Gemini 4 model (gemini-4-argon, gemini-4-carbon, gemini-4-neon, gemini-4-hydrogen) and those Flash helper models, otherwise background steps will return 404.
  • Use -high instead of -xhigh: agy builds request thinkingLevel from the model suffix (-low, -medium, -high); -xhigh is not supported on the API path yet.

Full setup reference: Antigravity CLI Custom Base URL Guide.


5. Team Governance: Per-Developer Spend Caps & Zero-Touch Key Rotation

Pointing all three CLIs at a single gateway endpoint solves more than protocol routing—it lets engineering managers enforce security and cost boundaries centrally instead of policing laptops.

1. One Key per Developer + Three-Tier Quotas

Never paste a shared org-wide API key into a team wiki. Issue one scoped API key per engineer (and separate keys for CI runners):

  • Group scoping: Attach Claude, OpenAI Codex, and Gemini Enterprise groups onto one developer key (or split per tool if you prefer), so GET /v1/models exposes exactly the approved model catalog.
  • Three-level spend caps (Key → Member → Department): Set a monthly or daily USD spend cap on each developer key alongside department budgets. If an unattended agent loop gets stuck retrying a failing test suite at 2 AM, the gateway trips HTTP 402 insufficient_quota on that single key while every teammate and production service keeps running unaffected.
  • Line-item chargeback: Export CSV usage logs filtered by member, department, or key creator—recording timestamp, model ID, input/cached/output token counts, latency, and exact USD charge—while failed requests rejected before generating output are billed at $0.

2. Key Rotation & Offboarding Without Touching Developer Laptops

When an engineer changes teams, loses a laptop, or leaves the organization:

  1. Instant server-side revocation: Revoke or disable only that engineer's key in the gateway console. Because no other laptop or CI pipeline shares that credential, zero teammates are disrupted.
  2. Centralized secret delivery for active rotations: Store each developer's HOPBASE_API_KEY in your team vault (1Password, Doppler, or macOS Keychain via MDM) and reference a single source variable across all three tools in ~/.zshrc:
# Single secret lookup feeds Claude Code, Codex CLI, OpenAI SDKs, and Antigravity CLI
export HOPBASE_API_KEY="$(op read 'op://Engineering/HopBase-Dev-Key/credential')"

export ANTHROPIC_BASE_URL="https://api.hop-base.com"
export ANTHROPIC_AUTH_TOKEN="$HOPBASE_API_KEY"

export OPENAI_BASE_URL="https://api.hop-base.com/v1"
export OPENAI_API_KEY="$HOPBASE_API_KEY"

export GOOGLE_GEMINI_BASE_URL="https://api.hop-base.com"
export GEMINI_API_KEY="$HOPBASE_API_KEY"
Enter fullscreen mode Exit fullscreen mode

When a scheduled 90-day key rotation runs in your secret manager, every developer's next terminal session picks up the rotated token across Claude Code, Codex CLI, and agy simultaneously.

3. Optional: Let Agents Check Their Own Quota via MCP

To eliminate "is my key out of quota or did I misspell the model ID?" support tickets, developers can register HopBase's read-only MCP management server right inside Claude Code:

claude mcp add --transport http hopbase https://api.hop-base.com/mcp \
  --header "Authorization: Bearer $HOPBASE_API_KEY"
Enter fullscreen mode Exit fullscreen mode

That exposes read-only tools (get_balance, get_key_info, list_models, get_usage, get_model_limits, search_docs) scoped strictly to the calling key—so an engineer can ask their terminal agent directly how much of their monthly spend cap remains or which exact model IDs their key can call.


Quick Verification Script for Team Onboarding

Drop this 15-line smoke test into your engineering onboarding repo so new hires can validate all three protocol surfaces in five seconds:

#!/usr/bin/env bash
set -euo pipefail
: "${HOPBASE_API_KEY:?Export HOPBASE_API_KEY first}"

echo "1/3 Checking authorized models..."
curl -fsS https://api.hop-base.com/v1/models \
  -H "Authorization: Bearer $HOPBASE_API_KEY" | jq -r '.data | "OK: \(length) models available"'

echo "2/3 Checking Anthropic Messages surface (Claude Code path)..."
curl -fsS https://api.hop-base.com/v1/messages \
  -H "x-api-key: $HOPBASE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-haiku-5-5","max_tokens":16,"messages":[{"role":"user","content":"Reply: ok"}]}' \
  | jq -r '.content[0].text'

echo "3/3 Checking OpenAI Responses surface (Codex CLI path)..."
curl -fsS https://api.hop-base.com/v1/responses \
  -H "Authorization: Bearer $HOPBASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6-luna","input":"Reply: ok"}' \
  | jq -r '.output_text // .output[0].content[0].text'
Enter fullscreen mode Exit fullscreen mode

For full tool-by-tool parameter references and troubleshooting error codes, bookmark the official integration guides:

Top comments (0)