Tokun

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:

ProtocolBase URLAuth header
OpenAI (Chat/Responses)https://api.tokun.sh/v1Authorization: Bearer sk-…
Anthropic (Messages)https://api.tokun.shx-api-key: sk-… (or Authorization: Bearer)
The Anthropic base URL has NO /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.

bash
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 statelessstore 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.

bash
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

StatusMeaningFix
401Missing or invalid API keySend a valid Tokun sk- key.
402Insufficient balance, or a per-key spend cap was hitTop up under Billing, or raise the key's cap.
404A /v1 was added to the Anthropic base URLUse https://api.tokun.sh (no /v1) for Messages.
400 — unknown modelModel id not recognizedUse a valid id; Tokun never substitutes a different model.
429 / 5xxRate-limited or upstream errorPassed through from the serving upstream; retry with backoff.
Billing is reserve-then-settle: a hold for the estimated max cost is placed at request time and settled from upstream-reported usage; a request that fails before forwarding is released without charge.