Claude Code & Agent Tools Integration

Connect Claude Code, OpenClaw, Cline, Roo Code and any Anthropic-protocol client to TokenHub.

Anthropic-NativeMulti-Provider FallbackOne Key, Both Protocols

1. How TokenHub Speaks Anthropic

TokenHub exposes two protocols simultaneously. The same th- key works on both — billing, usage, spend caps and provider fallback are unified.

ProtocolEndpointBase URL (paste this into the client)Typical clients
OpenAI-compatiblePOST /v1/chat/completionshttps://tokenhub.store/api/v1openai SDK, LiteLLM, LangChain
Anthropic-nativePOST /v1/messageshttps://tokenhub.store/apiClaude Code, OpenClaw, Cline, Roo Code, anthropic SDK

2. Available Claude Models

Use any of the IDs below as ANTHROPIC_MODEL or the model field. The anthropic/ prefix is optional — TokenHub accepts both forms.

Model IDTierInput ($/1M)Output ($/1M)
claude-opus-4-7Most capable$5.00$25.00
claude-opus-4-6Main flagship$5.00$25.00
claude-sonnet-4-6Production default$3.00$15.00
claude-haiku-4-5Lightweight, high-QPS$1.00$5.00
claude-opus-4-5Main flagship$5.00$25.00
claude-sonnet-4-5Production default$3.00$15.00

3. Three-Step Quick Start

Every supported client boils down to these three values. The rest of this page is just where to put them.

  1. 1
    Base URL → https://tokenhub.store/api
  2. 2
    Auth header → your TokenHub th- key (NOT an Anthropic key)
  3. 3
    ANTHROPIC_API_KEY=""Set ANTHROPIC_API_KEY="" explicitly so the SDK does not fall back to api.anthropic.com

4. Per-Client Configuration

Install

# macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash

# or via npm
npm install -g @anthropic-ai/claude-code

Option A — Shell environment variables (global)

# ~/.zshrc or ~/.bashrc
export ANTHROPIC_BASE_URL="https://tokenhub.store/api"
export ANTHROPIC_AUTH_TOKEN="th-your-tokenhub-key"
export ANTHROPIC_MODEL="claude-opus-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"
export ANTHROPIC_API_KEY=""    # must be empty, otherwise SDK falls back to api.anthropic.com

# then reopen the terminal and run:
cd /path/to/your/project
claude

Option B — Project-level config

.claude/settings.json

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://tokenhub.store/api",
    "ANTHROPIC_AUTH_TOKEN": "th-your-tokenhub-key",
    "ANTHROPIC_MODEL": "claude-opus-4-6",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5",
    "ANTHROPIC_API_KEY": ""
  }
}

Verify with /status

> /status
Auth token:        ANTHROPIC_AUTH_TOKEN
Anthropic base URL: https://tokenhub.store/api

If base URL still shows api.anthropic.com — ANTHROPIC_API_KEY is not empty, the terminal was not restarted, or the VSCode integrated terminal inherited stale env.

5. curl Self-Test

Non-streaming

curl -sS https://tokenhub.store/api/v1/messages \
  -H "x-api-key: th-your-tokenhub-key" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-6",
    "max_tokens": 128,
    "messages": [{"role":"user","content":"say hi"}]
  }'

Streaming SSE

curl -N -sS https://tokenhub.store/api/v1/messages \
  -H "x-api-key: th-your-tokenhub-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-opus-4-6","stream":true,"max_tokens":128,"messages":[{"role":"user","content":"count 1 to 3"}]}'

Event order: message_start → content_block_start → content_block_delta* → content_block_stop → message_delta → message_stop.

Repo smoke-test script

Runs 6 assertions in one shot (non-stream / Bearer / SSE order / auth errors / unsupported model / function calling).

BASE_URL=https://tokenhub.store TOKENHUB_API_KEY=th-xxxx \
  bash scripts/test-messages-api.sh

6. Troubleshooting Cheat Sheet

SymptomMost likely causeFix
401 / authentication_errorx-api-key not sent, or an Anthropic official key was passedUse a TokenHub th- key
402 / permission_errorAccount balance is 0, or the key's spend cap is exhaustedTop up via Dashboard → Billing, or remove the key's spend cap
400 'model not supported'Model ID typo / wrong caseCheck §2 — bare or anthropic/ prefix both accepted
503 'No upstream API key'Upstream key for this model is not yet provisionedContact support
Stream cuts off mid-wayClient HTTP idle timeout too smallRaise idle timeout to ≥ 120s
/status still shows api.anthropic.comANTHROPIC_API_KEY not unset, or terminal not restartedRun export ANTHROPIC_API_KEY="" then reopen the terminal
Tool call returns plain textRouted to an upstream with weak tool_use supportSwitch to claude-opus-4-6 / claude-sonnet-4-6, or contact support

7. FAQ

Looking for something else?

If you are calling Claude with the openai SDK, use the OpenAI-compatible guide instead.

Claude API (OpenAI-compatible) →