API Reference
Tokun exposes three request protocols on one metered pipeline: the OpenAI Chat Completions and Responses APIs, and the Anthropic Messages API. Pick whichever your client already speaks — the model id, billing, and routing are identical across all three.
Base URL & auth
Every request authenticates with a Tokun API key (starts with sk-) created in the console. The base URL depends on which protocol you call:
| Protocol | Base URL | Auth header |
|---|---|---|
OpenAI (Chat/Responses) | https://api.tokun.sh/v1 | Authorization: Bearer sk-… |
Anthropic (Messages) | https://api.tokun.sh | x-api-key: sk-… (or Authorization: Bearer) |
/v1 suffix — the Anthropic SDK appends the path itself. Use https://api.tokun.sh for Messages and https://api.tokun.sh/v1 for the OpenAI endpoints.Clients that can't set an Authorization header may embed the key as a URL path segment instead: POST /v1/{sk-key}/chat/completions.
POST /v1/chat/completions
The OpenAI Chat Completions API. Send the standard OpenAI request body with a Tokun model id; set "stream": true for an SSE token stream. Responses are byte-compatible with the official OpenAI shape.
curl https://api.tokun.sh/v1/chat/completions \
-H "Authorization: Bearer $TOKUN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-opus-4-8",
"messages": [{"role": "user", "content": "Say hello in one word."}]
}'POST /v1/responses
The OpenAI Responses API. Same auth and model ids as Chat Completions; use it if your SDK targets the Responses surface. It is stateless — store is always false, previous_response_id is rejected, and GET /v1/responses/{id} returns 404. Use the Anthropic Messages API if you need signed thinking blocks to round-trip across turns.
POST /v1/messages
The Anthropic Messages API — what the Anthropic SDKs and Claude Code speak. Buffered or streaming with the official Anthropic event protocol (signed thinking blocks round-trip on multi-turn tool use). Authenticate with x-api-key: sk-… or Authorization: Bearer.
curl https://api.tokun.sh/v1/messages \
-H "x-api-key: $TOKUN_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-opus-4-8",
"max_tokens": 64,
"messages": [{"role": "user", "content": "Say hello in one word."}]
}'POST /v1/messages/count_tokens
Returns a conservative token estimate for a Messages-shaped request. Free — no charge and no balance hold.
GET /v1/models
Lists the available model ids and per-model context windows. The response dialect follows the request: an Anthropic-native caller (sends x-api-key or anthropic-version) gets the Anthropic list shape; every other caller gets the OpenAI list format. Listing is free (no charge, no hold).
Errors
| Status | Meaning | Fix |
|---|---|---|
401 | Missing or invalid API key | Send a valid Tokun sk- key. |
402 | Insufficient balance, or a per-key spend cap was hit | Top up under Billing, or raise the key's cap. |
404 | A /v1 was added to the Anthropic base URL | Use https://api.tokun.sh (no /v1) for Messages. |
400 — unknown model | Model id not recognized | Use a valid id; Tokun never substitutes a different model. |
429 / 5xx | Rate-limited or upstream error | Passed through from the serving upstream; retry with backoff. |