Claude Code and AI Hub
Point Claude Code at AI Hub through its Anthropic Messages API and use any catalogue model.
1. Prepare your workspace
Create a dedicated workspace inference key in this AI Hub environment and set a spend cap. Claude Code resends its system prompt and about 25 tool definitions on every turn, so a small task can use tens of thousands of input tokens. Choose exact author/slug IDs with tools support from Models or the catalogue:
curl --fail "https://tokenhub-api.belive.sg/api/v1/models"2. Configure Claude Code
Set these in the environment Claude Code runs in, from your secret manager. Leave ANTHROPIC_API_KEY empty so Claude Code uses the AI Hub key and not an Anthropic login:
export ANTHROPIC_BASE_URL="https://tokenhub-api.belive.sg/api" export ANTHROPIC_AUTH_TOKEN="$TOKENHUB_API_KEY" export ANTHROPIC_API_KEY="" export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen/qwen3.8-flash" export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
Claude Code appends /v1/messages to ANTHROPIC_BASE_URL, so the base has no /v1. ANTHROPIC_DEFAULT_HAIKU_MODEL sets the model for Claude Code's background tasks; without it they use the main model. Use CLAUDE_CODE_SUBAGENT_MODEL to choose the subagent model.
3. Run
claude --model qwen/qwen3.8-maxClaude Code may log that it does not recognize a model ID such as qwen/qwen3.8-max; it still sends it. Check Activity for the model, usage and cost of each turn.
What AI Hub supports
- Messages on
/v1/messagesand/api/v1/messages, streamed or not, with tool use and tool results.Authorization: Bearerandx-api-keyare both accepted. cache_controlon system and message blocks is passed to the model's provider; whether a provider caches is up to that provider.- Ignored rather than refused: extended thinking, context management, output effort, server tools such as web search, and thinking blocks in earlier turns. They are listed in the
x-tokenhub-ignored-fieldsresponse header. - Refused with 400:
mcp_servers,containerand document (PDF) blocks./v1/messages/count_tokensis not served; Claude Code then estimates token counts itself.
Every catalogue model with tools support works through this API, but how well each one follows Claude Code's tools varies by model.
Troubleshooting
authentication_error: the key is not in the environment Claude Code runs in, or a stored Anthropic login orANTHROPIC_API_KEYis used instead. Run/statusto see the active credential source.not_found_errorfor the model: copy the exact catalogue ID, and check the key's model restrictions.- 404 for
/v1/v1/messages: remove/v1from the base. - For Claude Desktop, follow the Claude Desktop guide; shell variables are not its third-party inference settings.
Client support
For Claude Desktop, see the Claude Desktop guide.