API Reference
Token Hub exposes an OpenAI-compatible REST API. If you already use the OpenAI SDK, point it at our base URL and swap in your key — that's the whole migration.
Quickstart
Make your first request in three steps:
- Create a key in your dashboard — it looks like
sk-th-.... - Top up your balance with USDT or a Russian card.
- Send a request to the chat completions endpoint:
curl https://api.tokenhub.dev/v1/chat/completions \
-H "Authorization: Bearer sk-th-..." \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet",
"messages": [{"role": "user", "content": "Привет!"}]
}'Base URL
All endpoints are served under a single base URL:
https://api.tokenhub.dev/v1
Set this as the base_url (Python) or baseURL (Node) option of your OpenAI client.
Authentication
Authenticate every request with a bearer token in the Authorization header. Your key is prefixed with sk-th-.
Authorization: Bearer sk-th-...
Keep keys secret. Each key can be scoped with a model allowlist, IP allowlist, spend quota, and rate limit from your dashboard.
Endpoints
/v1/chat/completionsCreate a chat completion. Supports streaming, tools, and vision where the model allows./v1/embeddingsGenerate embedding vectors for one or more input strings./v1/modelsList the models your key is allowed to access, with pricing metadata.Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://api.tokenhub.dev/v1",
api_key="sk-th-...", # your Token Hub key
)
resp = client.chat.completions.create(
model="claude-3-5-sonnet", # any model, one key
messages=[{"role": "user", "content": "Привет!"}],
)
print(resp.choices[0].message.content)Node (openai)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.tokenhub.dev/v1",
apiKey: "sk-th-...", // your Token Hub key
});
const resp = await client.chat.completions.create({
model: "claude-3-5-sonnet",
messages: [{ role: "user", content: "Привет!" }],
});
console.log(resp.choices[0].message.content);Streaming
Pass stream: true to receive server-sent events. Tokens arrive as delta chunks and the stream ends with a data: [DONE] line — identical to the OpenAI streaming format.
stream = client.chat.completions.create(
model="claude-3-5-sonnet",
messages=[{"role": "user", "content": "Привет!"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")Error codes
Errors return a non-2xx status with a JSON body containing a code and message.
| Code | HTTP | Meaning |
|---|---|---|
invalid_api_key | 401 | The API key is missing, malformed, or revoked. |
insufficient_quota | 402 | Your balance is too low to cover the request. |
model_not_allowed | 403 | The key is not permitted to use the requested model. |
rate_limited | 429 | You exceeded the requests-per-minute limit for this key. |
upstream_unavailable | 502 | The upstream provider is temporarily unavailable. |