Docs

Set up Tokun, choose a model, and make your first API request.

Overview

What is Tokun?

One API, compatible with OpenAI and Anthropic clients, that meters your usage and routes each request to an eligible provider for the model you chose. Tokun routes across three kinds of providers, so the same model can be served at a lower cost.

Is it really the same model?

An individual model ID maps to one model (for example, anthropic/claude-opus-4-8 is Claude Opus 4.8). Whichever provider serves it, you get the same model at the same published rate. An official pool ID selects a member using that pool's routing rules. When you select a member explicitly, only that member can execute.

Quickstart

Set up with an AI assistant

Paste this prompt into your coding agent, such as Claude Code, Codex, or Cursor. It reads the setup guide at /llms.txt and configures Tokun for you. You only need to provide your API key.

text
Read https://tokun.sh/llms.txt and integrate Tokun into this project.

Set up manually

Change two settings: the base URL and the API key.

1. Create an API key

Sign in to the Tokun console, open API keys, and click Create key. The full key (sk-…) is shown only once, so copy it right away. After that, only a short prefix is stored and shown. Usage on a key is charged to your prepaid balance, so treat keys like passwords.

First, add funds on the Billing page. Each top-up can be $5–$1,000, paid through Stripe. A request with no balance returns 402 Payment Required.

2. Base URL and authentication

SettingValue
Base URLhttps://api.tokun.sh/v1
Auth headerAuthorization: Bearer sk-...
FormatOpenAI Chat Completions
EndpointPOST /v1/chat/completions (streaming via "stream": true)

3. Make your first request

curl:

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."}]
  }'

OpenAI SDK (Python):

python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.tokun.sh/v1",
    api_key="sk-...",  # your Tokun key
)

resp = client.chat.completions.create(
    model="anthropic/claude-opus-4-8",  # or "openai/gpt-5.5"
    messages=[{"role": "user", "content": "Say hello in one word."}],
)
print(resp.choices[0].message.content)

OpenAI SDK (Node):

node
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.tokun.sh/v1",
  apiKey: process.env.TOKUN_API_KEY, // your sk-... key
});

const resp = await client.chat.completions.create({
  model: "anthropic/claude-opus-4-8", // or "openai/gpt-5.5"
  messages: [{ role: "user", content: "Say hello in one word." }],
});
console.log(resp.choices[0].message.content);

4. Choose a model

Set the model field to a Tokun model ID or an official pool ID. Individual models use the lab/model format: the lab that made the model, then the model name. Tokun maps the ID to a provider and routes the request, so you never pass a provider's own model ID.

Model IDLab / poolList price
anthropic/claude-fable-5Anthropic$10.00 / $50.00 per 1M input / output tokens
anthropic/claude-fable-5-1Anthropic$10.00 / $50.00 per 1M input / output tokens
anthropic/claude-opus-4-5Anthropic$5.00 / $25.00 per 1M input / output tokens
anthropic/claude-opus-4-6Anthropic$5.00 / $25.00 per 1M input / output tokens
anthropic/claude-opus-4-7Anthropic$5.00 / $25.00 per 1M input / output tokens
anthropic/claude-opus-4-8Anthropic$5.00 / $25.00 per 1M input / output tokens
anthropic/claude-opus-5Anthropic$5.00 / $25.00 per 1M input / output tokens
anthropic/claude-opus-5-5Anthropic$4.00 / $20.00 per 1M input / output tokens
anthropic/claude-sonnet-4-5Anthropic$3.00 / $15.00 per 1M input / output tokens
anthropic/claude-sonnet-4-6Anthropic$3.00 / $15.00 per 1M input / output tokens
anthropic/claude-sonnet-5Anthropic$2.00 / $10.00 per 1M input / output tokens
anthropic/claude-haiku-4-5Anthropic$1.00 / $5.00 per 1M input / output tokens
openai/gpt-6-astraOpenAI$10.00 / $50.00 per 1M input / output tokens
openai/gpt-5.5OpenAI$5.00 / $30.00 per 1M input / output tokens
openai/gpt-5.6-solOpenAI$4.00 / $20.00 per 1M input / output tokens
openai/gpt-5.4OpenAI$2.50 / $15.00 per 1M input / output tokens
openai/gpt-5.3-codexOpenAI$1.75 / $14.00 per 1M input / output tokens
openai/gpt-5.6-terraOpenAI$2.00 / $12.00 per 1M input / output tokens
openai/gpt-4.1OpenAI$2.00 / $8.00 per 1M input / output tokens
openai/gpt-5.4-miniOpenAI$0.75 / $4.50 per 1M input / output tokens
openai/gpt-5-miniOpenAI$0.25 / $2.00 per 1M input / output tokens
openai/gpt-5.4-nanoOpenAI$0.20 / $1.25 per 1M input / output tokens
openai/gpt-5.6-lunaOpenAI$0.20 / $1.20 per 1M input / output tokens
openai/gpt-4.1-nanoOpenAI$0.10 / $0.40 per 1M input / output tokens
openai/gpt-5-nanoOpenAI$0.05 / $0.40 per 1M input / output tokens
gemini/gemini-3.1-pro-previewGoogle$2.00 / $12.00 per 1M input / output tokens
gemini/gemini-3.1-flash-lite-previewGoogle$0.25 / $1.50 per 1M input / output tokens
xai/grok-4.5xAI$2.00 / $6.00 per 1M input / output tokens
xai/grok-4.6xAI$2.00 / $6.00 per 1M input / output tokens
xai/grok-4.7xAI$2.00 / $6.00 per 1M input / output tokens
xai/grok-4.3xAI$1.25 / $2.50 per 1M input / output tokens
deepseek/deepseek-v4-proDeepSeek$1.32 / $3.96 per 1M input / output tokens
deepseek/deepseek-v4-flashDeepSeek$0.30 / $1.20 per 1M input / output tokens
deepseek/deepseek-v4.1-flashDeepSeek$0.30 / $1.20 per 1M input / output tokens
google/gemini-3.1-flash-liteGoogle$0.25 / $1.50 per 1M input / output tokens
minimax/MiniMax-M3MiniMax$0.30 / $1.20 per 1M input / output tokens
minimax/minimax-m2.5MiniMax$0.30 / $1.20 per 1M input / output tokens
minimax/minimax-m2.7MiniMax$0.30 / $1.20 per 1M input / output tokens
moonshot/kimi-k3Moonshot$3.00 / $15.00 per 1M input / output tokens
moonshot/kimi-k2.6Moonshot$0.95 / $4.00 per 1M input / output tokens
moonshot/kimi-k2.7-codeMoonshot$0.95 / $4.00 per 1M input / output tokens
qwen/qwen3.6-max-previewQwen$1.30 / $7.80 per 1M input / output tokens
qwen/qwen3.7-maxQwen$2.50 / $7.50 per 1M input / output tokens
qwen/qwen3-maxQwen$1.20 / $6.00 per 1M input / output tokens
qwen/qwen3.8-maxQwen$2.00 / $6.00 per 1M input / output tokens
qwen/qwen3.6-27bQwen$0.60 / $3.60 per 1M input / output tokens
qwen/qwen3.6-plusQwen$0.50 / $3.00 per 1M input / output tokens
qwen/qwen3.6-35b-a3bQwen$0.375 / $2.25 per 1M input / output tokens
qwen/qwen3.5-35b-a3bQwen$0.25 / $2.00 per 1M input / output tokens
qwen/qwen3.7-plusQwen$0.40 / $1.60 per 1M input / output tokens
qwen/qwen3-coder-nextQwen$0.30 / $1.50 per 1M input / output tokens
qwen/qwen3.8-flashQwen$0.15 / $0.47 per 1M input / output tokens
qwen/qwen3-vl-flashQwen$0.05 / $0.40 per 1M input / output tokens
qwen/qwen3.5-flash-02-23Qwen$0.10 / $0.40 per 1M input / output tokens
flash-poolTokun model pool$0.001 / request
z-ai/glm-5.1Z.ai$1.40 / $4.40 per 1M input / output tokens
z-ai/glm-5.2Z.ai$1.40 / $4.40 per 1M input / output tokens
z-ai/glm-5.3Z.ai$1.40 / $4.40 per 1M input / output tokens
z-ai/glm-5Z.ai$1.00 / $3.20 per 1M input / output tokens
z-ai/glm-4.5Z.ai$0.60 / $2.20 per 1M input / output tokens
z-ai/glm-4.7Z.ai$0.60 / $2.20 per 1M input / output tokens
z-ai/glm-4.5-airZ.ai$0.20 / $1.10 per 1M input / output tokens
z-ai/glm-5.3-flashZ.ai$0.15 / $0.50 per 1M input / output tokens

Official model pools

Official model pools appear in the model catalog and use a pool ID such as flash-pool. Choose an available pool from the live catalog; pool names and members are configured by Tokun administrators.

  • Fixed token pricing uses the pool's input, output, cache and context-tier rates for every member, including a member you select yourself.
  • Actual model pricing uses the serving member's price, frozen before the request. A retry to another member uses that member's frozen price.
  • Fixed per-request pricing charges once after an upstream success response begins. Missing usage, a partial response or a client disconnect after that point still counts once. Failures before success and unsuccessful retries do not add charges.

When the pool enables member selection, use pool-id/member-name, replacing the model's lab prefix with the pool ID. The selected member is the only model that can execute; the pool's pricing mode still applies. When selection is disabled, this form returns 400.

A pool stays listed when every member is unavailable. Calling it returns 503; requests never leave the pool to find another model.

This table is a snapshot of the catalog on September 24, 2026. For every current model and rate, see Models.

Model IDs are matched flexibly, so the IDs Claude Code and Codex send also work. You can send the lab/model ID above or just the model name (claude-haiku-4-5, gpt-5.4-mini); both resolve to the same model. A trailing context-window selector ([1m]), a provider or region prefix (anthropic/, us.anthropic.), and a trailing date stamp are accepted and ignored. An ID that doesn't match a served model returns unknown model. Tokun never substitutes a different model, so unsupported IDs like gpt-5.5-codex or gpt-5.2 return an error instead of billing you for the wrong model.

5. Connect a coding agent

If your agent runner lets you set an OpenAI base URL, set OPENAI_BASE_URL to the Tokun base URL and OPENAI_API_KEY to your sk-… key.

For step-by-step setup, see Use Tokun with Claude Code or browse all integration guides.

Codex: set the OpenAI environment variables and choose a Tokun model:

bash
export OPENAI_BASE_URL="https://api.tokun.sh/v1"
export OPENAI_API_KEY="sk-..."
# Then point Codex at a Tokun model id:
codex --model openai/gpt-5.5   # or: anthropic/claude-opus-4-8

OpenCLAW: point its OpenAI provider at the Tokun base URL, with environment variables or its config:

bash
OPENAI_BASE_URL=https://api.tokun.sh/v1
OPENAI_API_KEY=sk-...
OPENAI_MODEL=openai/gpt-5.5

Hermes: use the same base URL and key, and set the model to openai/gpt-5.5 or anthropic/claude-opus-4-8:

bash
OPENAI_BASE_URL=https://api.tokun.sh/v1
OPENAI_API_KEY=sk-...
# model: anthropic/claude-opus-4-8

Migrate to Tokun

What changes

Tokun supports the OpenAI and Anthropic API formats, so you only need to update your connection settings. For a standard text request, change these three values and keep the rest:

  • Base URL: https://api.tokun.sh/v1 for OpenAI clients, or https://api.tokun.sh (no /v1) for Anthropic clients.
  • API key: your Tokun sk- key, not your OpenAI or Anthropic key.
  • Model: a Tokun model ID in lab/model format, such as openai/gpt-5.5.
Before you switch, create a key on the API keys page and add funds on the Billing page. Requests return 402 when your balance is empty.
Tokun supports text requests on Chat Completions, Responses (stateless), and Anthropic Messages. Features Tokun doesn't support yet (embeddings, image generation, Responses store / previous_response_id state, and server-side tools) don't work as a drop-in replacement. If your app relies on them, check the API reference before you migrate.

From OpenAI

Keep the official OpenAI SDK. Set the base URL and key in the client constructor or with the OPENAI_BASE_URL / OPENAI_API_KEY environment variables, then pass a Tokun model ID. The OpenAI base URL keeps its /v1 suffix.

python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.tokun.sh/v1",   # was https://api.openai.com/v1
    api_key="sk-...",            # your Tokun key, not an OpenAI key
)

resp = client.chat.completions.create(
    model="openai/gpt-5.5",       # a Tokun lab/model id
    messages=[{"role": "user", "content": "Say hello in one word."}],
)

To avoid a code change, use environment variables. The OpenAI SDK reads both:

bash
export OPENAI_BASE_URL="https://api.tokun.sh/v1"
export OPENAI_API_KEY="sk-..."
The Responses API uses the same base URL and key. On Tokun it is stateless (no store / previous_response_id). Use the Anthropic Messages API if you need signed thinking blocks to round-trip across turns.

From Anthropic / Claude Code

Keep the Anthropic SDK or Claude Code. Set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY (a Tokun key), and pass a Tokun model ID. The Anthropic base URL has no /v1 suffix because the SDK adds the path itself.

bash
export ANTHROPIC_BASE_URL="https://api.tokun.sh"   # no /v1
export ANTHROPIC_API_KEY="sk-..."            # your Tokun key

# Claude Code, pinned to a Tokun model:
claude --model anthropic/claude-opus-4-8
A common mistake is adding /v1 to ANTHROPIC_BASE_URL, which returns a 404. Use https://api.tokun.sh exactly. For full setup steps, see the Claude Code guide.

Model IDs

Tokun model IDs use a lab/model format. Replace your provider's model name with the matching Tokun ID. The Models page lists every ID and its price.

  • OpenAI GPT models → openai/gpt-5.5 (and the other openai/* IDs).
  • Anthropic Claude models → anthropic/claude-opus-4-8 (and the other anthropic/* IDs).
Tokun never substitutes a different model. An unknown or mistyped ID returns an error instead of quietly routing to another model and billing you for it.

What stays the same

  • For supported text requests, request and response formats are byte-compatible with the official APIs, so your parsing code doesn't change.
  • Streaming ("stream": true / SSE) and tool or function calling work exactly as before.
  • The Anthropic event protocol round-trips signed thinking blocks in multi-turn tool use.
  • Your SDK, retry, and timeout logic stay as they are.
Billing is reserve-then-settle. When a request arrives, Tokun places a hold for its estimated maximum cost, then charges the usage the provider reports. If a request fails before it is forwarded, the hold is released and you are not charged.

Test your setup

Send one request, then check that it appears in your usage in the console:

bash
curl https://api.tokun.sh/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.5",
    "messages": [{"role": "user", "content": "Say hello in one word."}]
  }'

Troubleshooting

SymptomCauseFix
401Still sending your OpenAI or Anthropic keySend your Tokun sk- key.
402Empty Tokun balanceTop up on the Billing page.
404 (Anthropic)/v1 added to the Anthropic base URLUse https://api.tokun.sh with no /v1.
400 — unknown modelProvider's model name, not a Tokun IDUse a lab/model ID from the Models page.

Models

Official model pools

Official model pools appear in the model catalog and use a pool ID such as flash-pool. Choose an available pool from the live catalog; pool names and members are configured by Tokun administrators.

When the pool enables member selection, use pool-id/member-name, replacing the model's lab prefix with the pool ID. The selected member is the only model that can execute; the pool's pricing mode still applies. When selection is disabled, this form returns 400.

bash
# Set TOKUN_API_KEY and TOKUN_POOL_ID from your account and the live catalog.
curl "${TOKUN_BASE_URL:-https://api.tokun.sh/v1}/chat/completions" \
  -H "Authorization: Bearer $TOKUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\":\"$TOKUN_POOL_ID\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}],\"max_tokens\":64}"
bash
# The pool must enable member selection. TOKUN_MEMBER is the member name without its lab prefix.
curl "${TOKUN_BASE_URL:-https://api.tokun.sh/v1}/chat/completions" \
  -H "Authorization: Bearer $TOKUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\":\"$TOKUN_POOL_ID/$TOKUN_MEMBER\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}],\"max_tokens\":64}"

Every pool response echoes the model ID you sent: the pool ID for an automatic request, and pool-id/member-name when you selected a member. The canonical ID of the member that served the request travels in the tokun-resolved-model header, and in executed_public_model on the usage record. Your bill follows the configured pool pricing mode.

A pool stays listed when every member is unavailable. Calling it returns 503; requests never leave the pool to find another model.

Pool api_surfaces is the union of its members' supported APIs. Each request uses a member that supports its API format. Context and output limits are the minimum curated values across members; unknown limits are omitted. Pool count_tokens uses the first supported Anthropic member in routing order and returns its tokenizer count without a charge.

Lists the available model IDs and each model's context window. The response format follows the request: a caller that sends x-api-key or anthropic-version (as Anthropic clients do) gets Anthropic's list format; every other caller gets OpenAI's list format. Listing is free (no charge, no hold).

What does "served by" / served_vendor mean?

It is the provider that actually served a request, as reported by Tokun's routing layer (for example, anthropic or openai). Tokun records it as the served_vendor field on your usage, so you can see which provider handled each call. If the provider for a fanned-out request can't be determined, it is recorded as unattributed rather than left blank.

Coding agents

Can I use the Anthropic API format / Claude Code?

Yes. Tokun serves the Anthropic Messages API at POST /v1/messages (plus POST /v1/messages/count_tokens). To use an Anthropic SDK client or Claude Code, set ANTHROPIC_BASE_URL=https://api.tokun.sh and ANTHROPIC_API_KEY=sk-…, and set a Tokun model ID. Extended thinking is supported, with signed thinking blocks round-tripping in multi-turn tool use; image blocks are rejected. For setup steps, see Use Tokun with Claude Code.

Tokun also serves the Anthropic Messages API (POST /v1/messages). To use an Anthropic SDK client, including Claude Code, change the base URL and API key. Authenticate with the x-api-key header (Authorization: Bearer also works) and your sk-… key. The base URL has no /v1 suffix because the Anthropic SDK adds the path itself.

Claude Code: point it at Tokun and set a Tokun model ID:

bash
export ANTHROPIC_BASE_URL="https://api.tokun.sh"
export ANTHROPIC_API_KEY="sk-..."
export ANTHROPIC_MODEL="anthropic/claude-opus-4-8"
claude

Anthropic SDK (Python):

python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.tokun.sh",
    api_key="sk-...",  # your Tokun key
)

msg = client.messages.create(
    model="anthropic/claude-opus-4-8",  # or "openai/gpt-5.5"
    max_tokens=1024,
    messages=[{"role": "user", "content": "Say hello in one word."}],
)
print(msg.content[0].text)

Use Tokun model IDs (anthropic/claude-opus-4-8, openai/gpt-5.5). The API format and the model are independent, so the Anthropic SDK can call GPT models through this API too. Bare Anthropic model IDs (claude-opus-4-8, claude-haiku-4-5) resolve to the same model, so Claude Code's default model and /model picker work without a Tokun ID. An ID with no served match returns invalid_request_error; Tokun never substitutes a different model.

  • Supported: text conversations (buffered and streaming), system prompts (string or text blocks), client tools (tools / tool_use / tool_result), tool_choice, stop_sequences, temperature / top_p, POST /v1/messages/count_tokens (free, returns a conservative estimate). Prompt caching (cache_control) is honored and billed at cache rates on routes served in Anthropic's native format, and accepted but ignored on routes bridged to OpenAI Chat Completions.
  • Extended thinking is supported. Enable it with thinking: {type:"enabled", budget_tokens} (validated like the official API: budget ≥ 1024 and < max_tokens) or the output_config.effort setting. Responses include signed thinking blocks before the text (streaming emits thinking_delta / signature_delta events), and replayed thinking blocks round-trip upstream in multi-turn tool use. Extended thinking is forwarded unchanged whichever provider serves the request; nothing is stripped at runtime.
  • Not supported (rejected with invalid_request_error): image / document blocks, server tools other than Anthropic web search (e.g. code execution), mcp_servers, structured outputs via the deprecated top-level output_format (use output_config.format, which is supported). Anthropic web search is the exception: it is supported and billed on routes served in Anthropic's native format. max_tokens is required, as in the official API.
  • Errors use Anthropic's error format (authentication_error, invalid_request_error, billing_error on 402, …) with the same HTTP statuses as the OpenAI-compatible API.

Integration guides

Routing and price

Who actually serves my request?

A model can be served by several kinds of provider. The model is the same on each; what differs is who provides the capacity.

  • First-party: the model's developer or a first-party cloud. For anthropic/claude-opus-4-8 that is Anthropic; for cloud-hosted models it is a first-party cloud such as Google Vertex, Azure OpenAI, or AWS Bedrock.
  • Resellers: aggregators that resell official capacity, such as OpenRouter or GMI.
  • Independent providers: hosts that serve the same model at their own cost.

For an individual model, which provider serves your request does not change what you pay: the model has one published rate, the same on every API key. Model pools are priced by their own pricing mode. Your usage records show which provider served each request.

How can Tokun cost less?

Tokun can source the same model from a lower-cost provider instead of always paying the official list price, and publishes one price for that model regardless of who serves it. You get one API and one balance instead of arranging access with each provider yourself.

Can I choose which provider serves my request?

No. You choose the model (anthropic/claude-opus-4-8 or openai/gpt-5.5), and Tokun selects an eligible provider for it. There is no per-request provider selector, and a key you create carries no routing-channel setting. For an individual model, which provider served the request does not change what you pay. The served_vendor field on your usage records shows which provider was used.

Billing

How do pricing and billing work?

Billing uses a prepaid USD balance ($5–$1,000 per top-up, through Stripe). Individual models use their token rates. Model pools use one of three modes: fixed pool token rates for every member, the serving member's frozen token rates, or a fixed price per request. Token prices are quoted in USD per 1M tokens; per-request prices are quoted in USD per request.

Before forwarding, Tokun places a balance hold for the estimated maximum cost. Token-priced requests settle from the serving model's reported usage: an individual model at its published token rates, a model pool according to its pricing mode. Fixed per-request pools charge once after an upstream success response begins, even if usage is missing, the response is partial or the client disconnects. Failures before success release the hold; unsuccessful retries add no per-request charge.

Are there rate limits?

There is no fixed requests-per-second quota during the beta. Your limits are your prepaid balance and any per-key budget cap. A request is rejected with 402 when your balance cannot cover it, or 403 when the key is over its own budget cap. Providers may apply their own limits, which surface as 429. Tokun is a beta service with no uptime SLA.

Endpoints

Base URL and authentication

Authenticate every request with a Tokun API key (starts with sk-) from the API keys page. The base URL depends on the API format you call:

API formatBase URLAuth header
OpenAI (Chat Completions, 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 because the Anthropic SDK adds the path itself. Use https://api.tokun.sh for Messages and https://api.tokun.sh/v1 for the OpenAI endpoints.

If your client can't set an Authorization header, you can put the key in the URL path instead: POST /v1/{sk-key}/chat/completions.

POST /v1/chat/completions

The OpenAI Chat Completions API. Send a standard OpenAI request body with a Tokun model ID. Set "stream": true to stream tokens over SSE. Responses are byte-compatible with the official OpenAI format.

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, with the same authentication and model IDs as Chat Completions. Use it if your SDK targets the Responses API. 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/count_tokens

Returns a conservative token estimate for a Messages request. It is free: no charge and no balance hold.

Messages (Anthropic)

The Anthropic Messages API, used by the Anthropic SDKs and Claude Code. Buffered or streaming with the official Anthropic event protocol; signed thinking blocks round-trip in 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."}]
  }'

Errors

StatusMeaningFix
401Missing or invalid API keySend a valid Tokun sk- key.
402Your account balance cannot cover the requestTop up on the Billing page.
403The account has funds, but this key is over its own budget capSend the request with a key that has no budget cap, or create a key with a higher cap.
404/v1 added to the Anthropic base URLUse https://api.tokun.sh (no /v1) for Messages.
400 — unknown modelModel ID not recognizedUse a model or pool ID from the live catalog. An unknown ID does not select another model.
429 / 5xxRate limit or provider errorPassed through from the provider that served the request. Retry with backoff.
402 and 403 are different conditions. 402 is the account balance: the message is insufficient balance. 403 is the per-key budget cap: the message is credential budget exceeded. Tokun checks the balance first, so an empty account returns 402 even when the key is also over its cap. On Messages the same two statuses arrive in the Anthropic envelope, typed billing_error and permission_error.
Individual models use their token rates. Model pools use one of three modes: fixed pool token rates for every member, the serving member's frozen token rates, or a fixed price per request. Token prices are quoted in USD per 1M tokens; per-request prices are quoted in USD per request. Before forwarding, Tokun places a balance hold for the estimated maximum cost. Token-priced requests settle from the serving model's reported usage: an individual model at its published token rates, a model pool according to its pricing mode. Fixed per-request pools charge once after an upstream success response begins, even if usage is missing, the response is partial or the client disconnects. Failures before success release the hold; unsuccessful retries add no per-request charge.

FAQ

Is my data / prompt private?

Your prompts and completions pass through Tokun in transit to whichever upstream provider fulfills the request, and are processed transiently to operate and meter the Service. Tokun logs request metadata (timestamps, model, token counts, latency, status, which key) for billing and security — not the prompt/completion bodies as a product feature. The upstream provider that serves a request handles that content under its own terms and privacy policy. See the Privacy Policy.

Which endpoints exist?

POST /v1/chat/completions (buffered or streaming), POST /v1/responses (OpenAI Responses API, stateless), and POST /v1/messages (Anthropic Messages API) are the inference endpoints, and all three run the same metering pipeline. POST /v1/messages/count_tokens returns a free token estimate. GET /v1/models lists the available model IDs in the OpenAI format (same Authorization: Bearer key; listing is free). There is no /v1/embeddings endpoint today. Tokun also exposes /healthz and /readyz for liveness checks only.