All guides / Coding assistants

Use XHuoAPI in Claude Code

Claude Code sends requests in the Anthropic Messages format, which XHuoAPI accepts, so no proxy or converter is needed: two environment variables are enough. We ran real file-writing tasks with Claude Code 2.1.284, and the steps and notes below come from that test.

Before you start

Verify first

Before touching the tool, confirm the key and model work with curl. This rules out half of the 'I configured it and nothing happens' cases.

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek-v3.2","messages":[{"role":"user","content":"ping"}]}'

Steps

1

Install Claude Code (requires Node.js 18 or later).

npm install -g @anthropic-ai/claude-code
2

Set the environment variables. Leave /v1 off the base URL; Claude Code appends /v1/messages itself. Add these lines to ~/.zshrc or ~/.bashrc to keep them.

export ANTHROPIC_BASE_URL=https://api.xhuoapi.ai
export ANTHROPIC_AUTH_TOKEN=YOUR_XHUOAPI_KEY
export ANTHROPIC_MODEL=claude-sonnet-4-6
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-sonnet-4-6
3

Alternatively, leave your shell config alone and put the same values in the env block of ~/.claude/settings.json.

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.xhuoapi.ai",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_XHUOAPI_KEY",
    "ANTHROPIC_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-6"
  }
}
4

Run claude in your project directory for interactive mode, or use -p for a one-off task to confirm the connection first.

claude -p "Reply with the single word: ok"
5

To use a non-Claude model, change ANTHROPIC_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL to that model's ID, for example deepseek-v3.2.

export ANTHROPIC_MODEL=deepseek-v3.2
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v3.2

Notes

Test results (2026-10-06, asking Claude Code to create and write a file): claude-sonnet-4-6, deepseek-v3.2, glm-5.3 and qwen3.8-max all succeeded on the first try; kimi-k3 failed once and succeeded on retry. Speed varies a lot by model: the same task took about 9 s with DeepSeek and about 45 s with GLM.
Claude Code doesn't recognize model IDs such as deepseek-v3.2 or glm-5.3, so it assumes a 200K context window and auto-compacts the session at that size. Since 2.1.299 the output says "Claude Code doesn't recognize the model … assumes a context window of 200k tokens", plus an unrecognized_model line. That's expected and doesn't mean the connection failed. To compact at the model's real window, set CLAUDE_CODE_MAX_CONTEXT_TOKENS to that model's context length; to wait until the API reports the context is too long, set CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1 (which also hides that sentence). Re-tested on 2026-10-14 with 2.1.299 and deepseek-v4-flash, glm-5.3 and deepseek-v3.2: the file-writing task passed with each.
Claude Code 2.1.299 may print "We're changing auto mode to no longer charge for classifier requests … this session isn't eligible because your requests go through api.xhuoapi.ai". Per Claude Code's documentation this only means auto mode's classifier requests are billed as normal token usage; nothing stops working. To hide the notice, set CLAUDE_CODE_AUTO_MODE_SERVER=0.
Since 2.1.304, Claude Code turns tool search on by default behind a custom ANTHROPIC_BASE_URL (tool definitions are loaded on demand); if the gateway answers such a request with 400 or 422, Claude Code retries once without it. Tested on 2026-10-20 with 2.1.304 and glm-5.3, deepseek-v4.1-flash-none and deepseek-v3.2: the file-writing task passed with each, no extra setting needed.
Claude Code hands some background tasks to a Haiku-class model by default. Set ANTHROPIC_DEFAULT_HAIKU_MODEL to the model you are already using and know works, so background requests don't land on a model you haven't tested.
Claude Code sends a long system prompt with every request. In our test the first request wrote about 36K tokens to the prompt cache and later requests read about 64K tokens from it. Cache reads are billed at the cache price, which is lower than normal input; see the pricing page for each model.
ANTHROPIC_AUTH_TOKEN is sent as an Authorization: Bearer header and ANTHROPIC_API_KEY as x-api-key; XHuoAPI accepts both. With ANTHROPIC_API_KEY, interactive Claude Code asks for confirmation the first time it sees the key.
Qwen models and image models are only available in the Standard and Official tiers. A token created in the Saver or Spot tier will get a 'model not available' error for them.
The model ID must match the pricing page exactly (deepseek-v4-pro, not DeepSeek V4 Pro). Case and hyphens matter.

Commonly used models

These are common choices for this kind of tool; click a model to see its price in each tier. The full list is on the pricing page.

Which Chinese models work in Claude Code, Codex CLI, fx and OpenCode (tested) →

Steps follow the tool's current official documentation; the UI may change after updates. Tell us if something no longer matches.