C
Claude API Guide

Claude on TokenHub — OpenAI-Compatible Anthropic Models

Call Anthropic Claude models through the TokenHub unified /chat/completions endpoint. Fully OpenAI-compatible request and response format — no SDK migration required. Streaming, tool use (function calling) and vision (image input) are all supported. Billed per-token by model tier.

OpenAI-CompatibleStreamingTool UseVisionClaude 3 → 4.7Token-based

1Get Your API Key

  1. Visit tokenhub.store and register an account (GitHub / Google sign-in supported)
  2. Go to Dashboard → API Keys, click "Create New Key"
  3. Go to Dashboard → Billing to add Credits (1 Credit = $1 USD)
  4. Copy the API Key (format: th-xxxxxxxxxxxx...)
⚠️ The API Key is shown only once upon creation. Save it securely; if lost, create a new one.

2API Overview

Base URL

https://tokenhub.store/api/v1

Authentication

Pass the API Key in the Authorization header:

Header
Authorization: Bearer th-your-api-key

Endpoint (OpenAI-compatible)

POST
/chat/completions

Chat completion. Same schema as OpenAI /v1/chat/completions, including streaming, tool use, vision, and JSON mode.

You can keep using the official openai SDK — just point base_url to TokenHub and use your TokenHub API key. No other code changes are needed.

3Models & Pricing

Pricing is per 1 million tokens (USD). Only successful calls are charged. Both the canonical ID and the anthropic/* alias are accepted.

TierModel IDInputOutputNotes
Fable 5.1anthropic/claude-fable-5-1$10.00$50.00Latest, highest quality reasoning & coding.
Opus 5anthropic/claude-opus-5$5.00$25.00Latest, highest quality reasoning & coding.
Sonnet 5anthropic/claude-sonnet-5$2.00$10.00Latest, highest quality reasoning & coding.
Opus 4.8anthropic/claude-opus-4-8$5.00$25.00Latest, highest quality reasoning & coding.
Opus 4.7anthropic/claude-opus-4-7$5.00$25.00Latest, highest quality reasoning & coding.
Opus 4.6anthropic/claude-opus-4-6$5.00$25.00Latest, highest quality reasoning & coding.
Sonnet 4.6anthropic/claude-sonnet-4-6$3.00$15.00Flagship balance of quality and cost (recommended default).
Haiku 4.5anthropic/claude-haiku-4-5$1.00$5.00Fastest & cheapest 4-gen; great for high-QPS and classification.
Sonnet 4anthropic/claude-4-sonnet$3.00$15.00Previous-gen general-purpose workhorse.
Opus 4anthropic/claude-4-opus$15.00$75.00Latest, highest quality reasoning & coding.
3.5 Sonnetanthropic/claude-3-5-sonnet-latest$3.00$15.00Stable, production-proven; widely compatible.
3.5 Haikuanthropic/claude-3-5-haiku-latest$0.80$4.00Stable, production-proven; widely compatible.

4Request Parameters

ParameterTypeRequiredDefaultDescription
modelstringRequired—Claude model ID. Example: "anthropic/claude-sonnet-5". Both the anthropic/* prefixed form and the bare short name are accepted.
messagesarrayRequired—Chat history. Each item is { role, content }. role ∈ system | user | assistant. content is a string or an array of parts (for vision / tool results).
max_tokensintegerOptional1024Max output tokens (Claude requires this). Typical 1024–4096.
temperaturenumberOptional1.0Sampling temperature, 0.0–1.0. Lower = more deterministic.
top_pnumberOptional1.0Nucleus sampling. Use temperature OR top_p, not both.
streambooleanOptionalfalseIf true, returns Server-Sent Events (SSE) deltas.
stopstring[]Optional—Up to 4 stop sequences.
toolsarrayOptional—List of tool/function definitions for tool use (function calling).
tool_choicestring|objectOptionalautoControl tool selection: auto | none | required | { type:'function', function:{ name } }.
response_formatobjectOptional—JSON mode: { "type": "json_object" } forces the model to return valid JSON.
userstringOptional—Optional end-user ID for your own tracking.

5curl Examples

bash
curl https://tokenhub.store/api/v1/chat/completions \
  -H "Authorization: Bearer th-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-6",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Explain CAP theorem in 3 bullets."}
    ],
    "max_tokens": 512,
    "temperature": 0.3
  }'

6Python Example

python
from openai import OpenAI

client = OpenAI(
    api_key="th-your-api-key",
    base_url="https://tokenhub.store/api/v1",
)

resp = client.chat.completions.create(
    model="anthropic/claude-sonnet-4-6",
    max_tokens=512,
    temperature=0.3,
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Explain CAP theorem in 3 bullets."},
    ],
)

print(resp.choices[0].message.content)
print("usage:", resp.usage)

7JavaScript / Node.js Example

javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "th-your-api-key",
  baseURL: "https://tokenhub.store/api/v1",
});

const resp = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4-6",
  max_tokens: 512,
  temperature: 0.3,
  messages: [
    { role: "system", content: "You are a concise assistant." },
    { role: "user", content: "Explain CAP theorem in 3 bullets." },
  ],
});

console.log(resp.choices[0].message.content);
console.log("usage:", resp.usage);

8Usage Tips

  • Always set max_tokens — Claude treats it as required semantically. Without it, long generations may be truncated earlier than expected.
  • Put instructions in a single system message; keep user turns focused. Claude follows system prompts strongly.
  • For structured extraction, combine a system prompt like 'Return only JSON' with response_format: { type: 'json_object' }.
  • Streaming greatly improves perceived latency on long responses. The delta format matches OpenAI exactly.
  • Haiku-4-5 is ~5× cheaper than Sonnet-4-6 with similar capability for short-form tasks — route simple queries to Haiku to save cost.
  • Vision: pass images as { type: 'image_url', image_url: { url: 'https://...' } } inside the content array. Data URIs (base64) are also accepted.

9FAQ

Ready to Start?

Sign up for TokenHub and start calling Claude via our OpenAI-compatible API