API Reference

Overview

View Markdown

Endpoints and conventions for the asynchronous image API.

TokLab serves image, video, audio and text models through one API and one API key. Image, video and audio models run as asynchronous tasks: you submit a request, receive a task ID and poll for the result. Text models answer directly, in the request format of the model's vendor.

Base URL

https://api.toklab.ai

Use HTTPS and send JSON request bodies. The audio endpoints take a multipart/form-data upload instead.

Authentication

Send your key as a Bearer token on every request, including task queries:

Authorization: Bearer YOUR_API_KEY

The Anthropic Messages endpoint also accepts the key in x-api-key, together with the anthropic-version header. See Authentication.

Media task endpoints

MethodPathPurpose
POST/v1/images/generationsSubmit an image generation or editing task: GPT Image, Nano Banana and Midjourney.
POST/v1/videos/generationsSubmit a video task: Seedance 2.5 and 2.0 (ModelArk request body), Veo 3.1, Kling 3.0, MiniMax H3 and SD Video.
POST/v1/audio/transcriptionsSubmit an audio file for transcription with Whisper-1.
POST/v1/audio/translationsSubmit an audio file for translation into English with Whisper-1.
GET/v1/tasks/{id}Read the state and result of an image, video or audio task.

Reference images, videos and audio are passed as URLs in the request body. An image request becomes an edit when it includes input images. Each model's reference lists its parameters.

Text endpoints

MethodPathRequest format
POST/v1/chat/completionsOpenAI Chat Completions
POST/v1/responsesOpenAI Responses
POST/v1/messagesAnthropic Messages
POST/v1beta/models/{model}:generateContentGoogle Gemini
POST/v1beta/models/{model}:streamGenerateContentGoogle Gemini, streamed
GET/v1/modelsList the available models

Not every text model supports every format. The model's API reference names the formats it accepts; for example, Claude Opus 5.5 accepts Chat Completions, Responses and Messages, while the Gemini text models use the /v1beta paths.

Request lifecycle

Media tasks

  1. Submit the request. The response is a task, not the finished file: store its id.
  2. Poll the task until it reaches a final state. Tasks on /v1/tasks/{id} report processing, then completed or failed.
  3. Read the result. Images are in output.data[].url, videos in output.video_url, and Whisper output in output.url. Every result link points to TokLab's storage.

On failure, inspect error.code and error.message. Failed tasks are not charged. There is no completion webhook; poll the task instead, as described in Webhooks.

Text requests

A text request returns the model's answer in the same response, in the vendor's official response shape. Set stream to true, or use :streamGenerateContent for Gemini, to receive server-sent events. Text models are billed per token.

Next steps