The complete tokgate.io API reference
Unified authentication and metering, with protocol selected by model vendor: Anthropic models use Anthropic Messages, Google models use the native Gemini format, and other LLMs use the OpenAI-compatible format.
Overview
tokgate.io provides a RESTful API. All AI model capabilities share the same data-plane gateway and the same API key — you do not need to integrate an SDK or maintain credentials separately for each model provider.
- Chat routes by vendor: Anthropic → Messages, Google → native Gemini, other LLMs → OpenAI Chat Completions. The three formats are not interchangeable.
- Images use each vendor's native endpoint, request body and parameters. Gemini, GPT Image, Seedream and Qwen Image formats are not interchangeable.
- Video uses asynchronous tasks: submit a generation task, save the task ID, then poll for status and output.
AI Model APIs
Chat
Chat completions with multi-turn conversations, streaming and tool use. The model vendor determines the format: OpenAI-compatible, Anthropic Messages, or native Gemini.
ChatImages
AI image generation and editing through vendor-native protocols: Gemini Image, gpt-image-2, seedream-5-0 and qwen-image-3.0-pro.
Videos
Asynchronous video generation APIs for the seedance and happyhorse series, with task submission, status polling and output retrieval.
Authentication
All endpoints authenticate with an API key, created on the console's "API Keys" page and starting with sk-. Login cookies are not used.
OpenAI format
Authorization: Bearer sk-***
Content-Type: application/json
Anthropic format
The official Anthropic SDK uses the x-api-key header and requires a version number. Both styles are supported; with the official SDK, use the first one below.
x-api-key: sk-***
anthropic-version: 2023-06-01
Content-Type: application/json
# Or keep the Bearer style
Authorization: Bearer sk-***
anthropic-version: 2023-06-01
Content-Type: application/json
Native Gemini format
Google models use Gemini-native request structures and authenticate with Authorization: Bearer ....
Authorization: Bearer sk-***
Content-Type: application/json
Do not send x-goog-api-keyIf this header is present, the request returns 401 even when a valid Authorization: Bearer header is also sent. Google's official Gen AI SDK uses this header by default, so override it with a Bearer header when integrating. The ?key= URL parameter is not supported either.
Key scope affects available modelsIf a model whitelist is set when creating a key, models outside the whitelist return 403; if a spending quota is set, the key returns an insufficient-quota error once its quota is used up, without affecting other keys on the account.
Endpoint list
| Method | Path | Description |
|---|---|---|
| GET | /v1/models | List models available to the current key |
| POST | /v1/chat/completions | Chat completions (OpenAI format), with streaming and tool calling |
| POST | /v1/messages | Anthropic model messages (Anthropic format) |
| POST | /v1beta/models/{model}:generateContent | Google content generation, including Gemini image generation (native Gemini format) |
| POST | /v1beta/models/{model}:streamGenerateContent | Google model streaming content generation (native Gemini format) |
| POST | /v1/images/generations | GPT Image generation (text to image) |
| POST | /v1/images/edits | GPT Image editing (image to image / inpainting) |
| POST | /api/v3/images/generations | Seedream image generation and editing |
| POST | /api/v1/services/aigc/multimodal-generation/generation | Qwen Image generation and editing |
| POST | /api/v3/contents/generations/tasks | Submit a seedance-series video generation task |
| GET | /api/v3/contents/generations/tasks/{id} | Query seedance task status and output |
| POST | /api/v1/services/aigc/video-generation/video-synthesis | Submit a happyhorse-series video generation task |
| GET | /api/v1/tasks/{task_id} | Query happyhorse task status and output |
Video APIs use asynchronous tasksSeedance and HappyHorse return a task ID after submission. Save it, poll the matching query endpoint, and download and store the output promptly after success.
Error codes
Use the business code to identify the failure precisely. The HTTP status and message shown here are the gateway defaults.
| Business code | Default HTTP | Default message | Typical scenario |
|---|---|---|---|
GW-400 | 400 | Invalid request body or missing model. | |
GW-401 | 401 | Missing, invalid or expired sk; account not found or disabled. | |
GW-402 | 402 | Insufficient quota or balance (general). | |
GW-402-1 | 402 | Pay-per-use balance exhausted. | |
GW-402-2 | 402 | Plan credits exhausted. | |
GW-403 | 403 | Input or output blocked by content moderation. | |
GW-403-1 | 403 | API key model whitelist rejected the request. | |
GW-404 | 404 | Model not found or not published. | |
GW-404-1 | 404 | Unknown route or resource not found. | |
GW-413 | 413 | Request or response body exceeds the buffer limit. | |
GW-422 | 422 | Route resolution failed or provider credentials are unavailable. | |
GW-429 | 429 | Account, key or provider RPM or concurrency limit reached. | |
GW-500 | 500 | Gateway internal exception or uncaught error. | |
GW-502 | 502 | Upstream 4xx/5xx response, connection failure or timeout. |
Rate limits & retries
- RPM: each key can have its own per-minute request cap; blank means unlimited. Edit it on the console's "API Keys" page.
- Spending quota: each key can have a cumulative spending cap (USD); the key is automatically deactivated once it is reached.
- Retry policy: use exponential backoff (e.g. 1s, 2s, 4s) for
429and5xx, with a maximum retry count to avoid cascading failures. - Timeouts: enable streaming for chat to improve time-to-first-token; images return synchronously but take longer, so do not set the client timeout too short; video is task-based — always poll instead of holding a long-lived connection.
- Idempotency: after a video task is submitted, save the returned task ID and poll it. Do not resubmit — resubmitting creates a new task and is billed again.
Next steps
- Chat — requests and streaming for the OpenAI, Anthropic and Gemini vendor protocols.
- Images — vendor-native references for Gemini Image, gpt-image-2, seedream-5-0 and qwen-image-3.0-pro.
- Videos — asynchronous task APIs for the seedance and happyhorse series, including submission, polling and output retrieval.