Docs

One OpenAI-compatible endpoint for every model on the gateway. Three steps to your first billed request.

1 · Get an API key

Sign in to the console and open Tokens. Create a key, copy it and store it somewhere safe — the console only shows it in full once. Keys are bearer credentials: anyone who has one can spend your balance, so treat it like a password and give a separate key to each application.

You also need a positive balance before the first call: top up in Wallet in the console. Requests stop when the balance reaches zero instead of running up a bill.

2 · Point your client here

Everything lives behind one base URL and one header:

Base URL   https://api.tokwork.com/v1
Header     Authorization: Bearer <your-api-key>

Because the surface is OpenAI-compatible, most SDKs only need the base URL and the key changed. Requests in the Anthropic and Gemini formats are accepted as well.

3 · Make the first call

Generate an image from the command line:

curl https://api.tokwork.com/v1/images/generations \
  -H "Authorization: Bearer $TOKWORK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "An orange cat at sunset, watercolour",
    "size": "1024x1024"
  }'

The response carries the image twice — once inline, once as a hosted URL:

{
  "created": 1791610498,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUg…",   // base64 PNG
      "url": "https://…/1791610498419702800.png",      // hosted copy
      "width": 1024,
      "height": 1024,
      "revised_prompt": "An orange cat at sunset, watercolour"
    }
  ],
  "usage": { … }                                     // per-request usage detail
}

With the official OpenAI SDKs, keep your code and change two lines: base_url to https://api.tokwork.com/v1 and api_key to your TokWork key.

Image sizes and prices

Image models are billed per image, and the price depends on the output size — the request’s size is matched to a tier by its long edge:

TierLong edge of the outputExample size
0.5Kup to 640 px512x512
1Kup to 1280 px1024x1024
2Kup to 2560 px2048x2048
4Kabove 2560 px4096x4096

Leave size empty or set it to auto and the cheapest tier is used. Per-model prices, including the size breakdown, are on the pricing page and in the console — they are generated from the gateway, so they are current.

Endpoint reference

MethodPathWhat it does
GET/v1/modelsList the models your key can call today, with their pricing metadata.
POST/v1/images/generationsGenerate an image. Returns base64 plus a hosted URL.
POST/v1/chat/completionsOpenAI-compatible chat. Enabled per model as text models come online.

GET /v1/models is the source of truth for what your key can call right now — it is the same list that powers the console and the pricing page. Today the gateway serves image generation models; text and chat models are enabled model by model, and a model that is not enabled yet answers with 503 model_not_found rather than a silent fallback.

Errors

Errors use the OpenAI error envelope, and every response carries a request id you can quote to support:

{
  "error": {
    "message": "No available channel for model … (request id: …)",
    "type": "new_api_error",
    "code": "model_not_found"
  }
}
StatusMeaning
401Missing or invalid key. Check the Authorization header.
402Balance exhausted. Top up in the console and retry.
429Rate limited. Back off and retry.
503No channel can serve that model right now — including models that are not enabled yet.

A failed request is not charged. Every successful one is logged with the model, the size and the amount deducted, so you can reconcile spend in Logs.

Need help?

Mail support@tokwork.com with the request id and the model name, or use the contact form. We answer within one business day.