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:

  1. Create a key in your dashboard — it looks like sk-th-....
  2. Top up your balance with USDT or a Russian card.
  3. 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

POST/v1/chat/completionsCreate a chat completion. Supports streaming, tools, and vision where the model allows.
POST/v1/embeddingsGenerate embedding vectors for one or more input strings.
GET/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.

CodeHTTPMeaning
invalid_api_key401The API key is missing, malformed, or revoked.
insufficient_quota402Your balance is too low to cover the request.
model_not_allowed403The key is not permitted to use the requested model.
rate_limited429You exceeded the requests-per-minute limit for this key.
upstream_unavailable502The upstream provider is temporarily unavailable.