Quick integration

TokenHub is OpenAI-compatible — swap the BaseURL and call every model. Native Anthropic / Claude Code protocol, Gemini protocol and OpenAI Responses are supported too.

Quick start

  1. Get an API key

    Sign up and create a key (sk-...) on the console API keys page. The full key is shown only once at creation — store it safely.

    Open console
  2. Swap the BaseURL

    Point your request base URL at our gateway; everything else stays identical to the OpenAI API:

    https://api.tokenhub.example/v1
  3. Make a call

    Replace sk-... in the examples below with your own key and send your first request.

Code examples

Three common endpoints: OpenAI Chat Completions, OpenAI Responses and Anthropic Messages.

cURL · Chat Completions
curl https://api.tokenhub.example/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -d '{
    "model": "openai/gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
cURL · Responses
curl https://api.tokenhub.example/v1/responses \
  -H "Authorization: Bearer sk-..." \
  -d '{
    "model": "openai/gpt-4o",
    "input": "Write a haiku about APIs."
  }'
cURL · Messages (Anthropic)
curl https://api.tokenhub.example/v1/messages \
  -H "x-api-key: sk-..." \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

OpenAI SDK

Official SDKs only need a base_url override; model names keep the vendor/model format.

Python
from openai import OpenAI

client = OpenAI(
    api_key="sk-...",
    base_url="https://api.tokenhub.example/v1",
)

resp = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
Node.js
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-...",
  baseURL: "https://api.tokenhub.example/v1",
});

const resp = await client.chat.completions.create({
  model: "openai/gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(resp.choices[0].message.content);

Claude Code / native Anthropic protocol

We serve the native Anthropic /v1/messages protocol. Claude Code needs two environment variables:

Environment variables
export ANTHROPIC_BASE_URL="https://api.tokenhub.example"
export ANTHROPIC_AUTH_TOKEN="sk-..."

Or call /messages directly:

cURL · Messages (Anthropic)
curl https://api.tokenhub.example/v1/messages \
  -H "x-api-key: sk-..." \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Model names

Model IDs use the vendor/model format, e.g. openai/gpt-4o, anthropic/claude-sonnet-4, google/gemini-2.5-pro. See the model catalog for the full list with live prices.

Browse the model catalog

Common errors

StatusMeaningHow to fix
401Key invalid or deletedCheck the Authorization header is Bearer sk-..., or create a new key in the console
402Insufficient balanceTop up in the console wallet, or subscribe to a plan for discounted rates
429Rate limitedLower concurrency or retry later; plan subscribers get higher limits

Documentation

All integration docs, grouped by topic.

5 groups · 28 documents