本服务面向非中国大陆地区 · ZetaAPI.AI 的网站与控制台主要面向非中国大陆市场,注册与开通功能在你当前地区不可用。

Configure ZetaAPI in Claude Code

Point Claude Code (Anthropic's official CLI) at ZetaAPI in 30 seconds and get 0.3x–0.4x of official pricing, with prompt cache support.

Updated 2026-09-03

When to use this

Claude Code is Anthropic’s official terminal CLI; after installing it with npm i -g @anthropic-ai/claude-code you can call Claude interactively in any local directory. ZetaAPI exposes a /v1/messages endpoint fully compatible with the official Anthropic API, so switching the upstream only takes two environment variables.

Prerequisites

Setup

1. Set the environment variables

Add to your shell config (~/.zshrc / ~/.bashrc):

export ANTHROPIC_BASE_URL="https://api.zetaapi.ai"
export ANTHROPIC_API_KEY="sk-your-zetaapi-key"

Reload the config:

source ~/.zshrc

2. One-line install (optional)

If you’d rather not edit the shell config by hand, one command does it:

npx --prefer-online zetaapi@latest setup claude-code

It writes ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN into the env block of ~/.claude/settings.json (any existing file is backed up as settings.json.bak.<timestamp> first) and verifies connectivity. When prompted, paste an Install Token (from the console’s “Setup configuration” / “Connect new tool” dialog, starts with ze_inst_, valid for 5 minutes) or paste an API Key (sk-) directly; for CI / non-interactive runs append --token=ze_inst_xxx or set ZETAAPI_TOKEN.

3. Verify

In any project directory, run:

claude

After your first prompt, the console dashboard immediately shows the call’s token usage and cost.

FAQ

Q: Why am I getting 401 Unauthorized?

Check that ANTHROPIC_API_KEY is a ZetaAPI key (starts with sk-), not an official Anthropic sk-ant- key.

If you configured via npx zetaapi setup, the credential lives in env.ANTHROPIC_AUTH_TOKEN inside ~/.claude/settings.json — check that key rather than the environment variable.

Q: Is prompt cache supported?

Yes. Claude Code enables ephemeral cache control by default; ZetaAPI passes the original cache behavior through, and cache reads are billed at 10% of the input price — same as official.

Q: Why is Sonnet’s context only 200K? How do I get the full 1M?

When Claude Code points at a third-party base URL, it cannot verify whether the endpoint supports the 1M-token context window, so it conservatively budgets 200K. This is client-side behavior, not a ZetaAPI limit.

Set it explicitly once per session:

/model sonnet[1m]

You can also run /model and pick the entry labeled 1M context. The [1m] marker is a Claude Code directive only — it is stripped before the request is sent, so the model name ZetaAPI receives is still claude-sonnet-5. No extra configuration is needed on our side.

ZetaAPI has served Sonnet contexts of over 600K tokens in production, and Opus up to roughly 900K. Note that very long contexts resend the full history on every turn, so token consumption rises sharply — tune it together with the compact threshold below.

Q: Can I turn off auto-compact?

Yes. Add this to ~/.claude/settings.json:

"autoCompactEnabled": false

Raising the trigger threshold is usually better than turning it off entirely:

/autocompact 500k

Accepted values run from 100K to 1M and are capped at the current model’s context window. For scripts and CI, use the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable (plain token count only, e.g. 500000); claude --autocompact 500k applies to a single launch.

Once auto-compact is off, filling the context makes Claude Code raise Prompt is too long and stop, instead of summarizing the history and continuing. If compaction merely feels too frequent, raising the threshold is more practical than disabling it.

Q: How do I switch back to official?

Remove or comment out ANTHROPIC_BASE_URL and set ANTHROPIC_API_KEY back to your official Anthropic key. If you configured via npx zetaapi setup, delete ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN from the env block of ~/.claude/settings.json instead (a .bak.<timestamp> backup is available).