API Reference

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.

API Host https://api.tokgate.io
  • 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

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

MethodPathDescription
GET/v1/modelsList models available to the current key
POST/v1/chat/completionsChat completions (OpenAI format), with streaming and tool calling
POST/v1/messagesAnthropic model messages (Anthropic format)
POST/v1beta/models/{model}:generateContentGoogle content generation, including Gemini image generation (native Gemini format)
POST/v1beta/models/{model}:streamGenerateContentGoogle model streaming content generation (native Gemini format)
POST/v1/images/generationsGPT Image generation (text to image)
POST/v1/images/editsGPT Image editing (image to image / inpainting)
POST/api/v3/images/generationsSeedream image generation and editing
POST/api/v1/services/aigc/multimodal-generation/generationQwen Image generation and editing
POST/api/v3/contents/generations/tasksSubmit 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-synthesisSubmit 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 codeDefault HTTPDefault messageTypical scenario
GW-400400Bad request parametersInvalid request body or missing model.
GW-401401Authentication failedMissing, invalid or expired sk; account not found or disabled.
GW-402402Insufficient account balance or quotaInsufficient quota or balance (general).
GW-402-1402Insufficient balance. Your pay-per-use balance is exhausted, please recharge your account.Pay-per-use balance exhausted.
GW-402-2402Insufficient credits. Your plan credits are exhausted, please purchase a plan.Plan credits exhausted.
GW-403403Content moderation rejectedInput or output blocked by content moderation.
GW-403-1403Current key is not authorized to access this modelAPI key model whitelist rejected the request.
GW-404404Model not found or routing failedModel not found or not published.
GW-404-1404Requested resource not foundUnknown route or resource not found.
GW-413413Request payload exceeds maximum allowed sizeRequest or response body exceeds the buffer limit.
GW-422422Request routing failedRoute resolution failed or provider credentials are unavailable.
GW-429429Too many requests, rate limitedAccount, key or provider RPM or concurrency limit reached.
GW-500500Gateway internal errorGateway internal exception or uncaught error.
GW-502502Upstream service errorUpstream 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 429 and 5xx, 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.