OpenAI SDKs
Set base_url or baseURL to https://api.tokza.ai/v1. Start with Chat Completions unless the selected model declares Responses support.
Start with the OpenAI-compatible interface, discover what your account can use, and treat every model’s capability labels as the source of truth for alternate formats.
Tokza’s public catalog returned 456 model records. The authorization guard was observed for Models, Chat Completions, Responses, Embeddings and Images. These checks did not use a real key and do not prove a successful downstream model call, price, latency or route availability for every account.
Direct public Tokza HTTP behavior.
A model-level compatibility label, not a universal promise.
A common interface shape; confirm the selected model supports it.
Confirm the exact account-visible route and schema before use.
Getting started
Tokza account sessions and Tokza API keys are different credentials. Use the account portal to create, name, limit and revoke API keys. Send an API key only in the HTTPS Authorization header; never put it in a browser bundle, source repository, URL or prompt.
Register at api.tokza.ai/register or sign in.
Use a clear name, the smallest necessary access, and an account/workspace spend limit where available.
Load it from a protected secret manager or environment variable and rotate it after suspected exposure.
Authorization: Bearer $TOKZA_API_KEY
First request
Call GET /v1/models first and select a model returned to your key. The examples use gpt-4o-mini only as an illustrative model observed in the public catalog on August 14, 2026.
curl https://api.tokza.ai/v1/chat/completions \
-H "Authorization: Bearer $TOKZA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKZA_API_KEY"],
base_url="https://api.tokza.ai/v1",
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.TOKZA_API_KEY,
baseURL: "https://api.tokza.ai/v1",
});
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(response.choices[0].message.content);
For Chat Completions, read generated text from choices[0].message.content. Store the response id, selected model, and usage fields when returned; exact usage fields can vary by route.
{
"id": "chatcmpl_example",
"object": "chat.completion",
"model": "gpt-4o-mini",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "Hello from Tokza."},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 14, "completion_tokens": 5, "total_tokens": 19}
}
Routing
The primary integration surface is the OpenAI-compatible base below. Do not append a second /v1 when an SDK accepts a complete base URL.
https://api.tokza.ai/v1Observed| Interface | Use it when | Availability rule |
|---|---|---|
| OpenAI compatible | Chat, common SDKs, embeddings, images and compatible tools. | Model is returned to your key and marked openai. |
| Responses | You need item-based inputs/outputs or a Responses-compatible model. | Model is marked openai-response. |
| Native Anthropic | Your application requires an Anthropic-native message contract. | Model is marked anthropic; confirm the exact account-visible base and route. |
| Native Gemini | Your application requires Gemini-native content parts. | Model is marked gemini; confirm the exact account-visible base and route. |
| Provider-specific media | A model uses asynchronous video, music or image operations. | Use only the route and schema displayed for that model in your account. |
Discovery
Model names, availability and supported formats change. Make GET /v1/models part of onboarding and cache the result briefly rather than shipping a permanent list.
/v1/modelsObservedcurl https://api.tokza.ai/v1/models \
-H "Authorization: Bearer $TOKZA_API_KEY"
supported_endpoint_types. A model can be OpenAI-compatible without supporting Responses, native Anthropic, native Gemini, images, audio or another specialized format.Catalog-declared On August 14, 2026, the public catalog contained labels for OpenAI, Responses, Anthropic, Gemini, image generation/editing, speech, embeddings, rerank, realtime and asynchronous media. Treat those labels as routing hints and validate a capped request before production.
Text and chat
/v1/chat/completionsObservedSend an ordered messages array. Common roles are system, user, assistant and tool, but accepted fields and limits depend on the selected model.
{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "Answer concisely."},
{"role": "user", "content": "Give me three names for an analytics feature."}
],
"temperature": 0.3,
"max_tokens": 120
}
| Field | Required | Guidance |
|---|---|---|
model | Yes | Use an ID returned to your API key. |
messages | Yes | Ordered conversation state; resend the history needed for the next turn. |
temperature | No | Support/range can vary. Omit it when a reasoning model rejects sampling controls. |
max_tokens | No | Some models use a different output-token field. Follow the selected model contract. |
stream | No | Set true only if the route/model supports streaming. |
Item-based generation
/v1/responsesObservedUse Responses only with a model marked openai-response. Its input/output items differ from Chat Completions; do not assume choices[0] exists.
curl https://api.tokza.ai/v1/responses \
-H "Authorization: Bearer $TOKZA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "Explain exponential backoff in 50 words."
}'
Incremental output
Standard-compatible For compatible routes, set stream: true and consume Server-Sent Events until the terminal event. Event payloads differ between Chat Completions and Responses.
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Write a two-line poem."}],
stream=True,
)
for event in stream:
delta = event.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
/v1/realtimeCatalog-declaredThe public catalog maps its realtime capability to this route. Before adoption, confirm the authenticated session bootstrap, transport, ephemeral-key policy, event names, audio formats and termination behavior for the selected model. A catalog path alone does not establish a WebSocket or WebRTC contract.
Controlled output
Standard-compatible Tool calling and JSON-schema output are model-dependent. Validate support with the selected model and never execute tool arguments without application authorization and schema validation.
{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Weather in Rome?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Return current weather for one city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": false
}
}
}]
}
Validate the tool name and arguments, enforce per-user authorization, execute the function in your application, then send a tool-result message tied to the returned call ID. Model selection is not permission to perform the action.
Multimodal input
Conditional Use image content only with a model whose account-visible contract supports vision. Prefer short-lived HTTPS URLs or accepted data URLs, and do not assume every OpenAI-compatible chat model accepts image parts.
{
"model": "<VISION_MODEL_FROM_V1_MODELS>",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Describe the chart."},
{"type": "image_url", "image_url": {"url": "https://example.com/chart.png"}}
]
}]
}
Confirm accepted MIME types, size limits, URL-fetch policy, detail controls and retention before sending sensitive media.
Retrieval
/v1/embeddingsObservedcurl https://api.tokza.ai/v1/embeddings \
-H "Authorization: Bearer $TOKZA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"<EMBEDDING_MODEL_FROM_V1_MODELS>","input":["First document","Second document"]}'
Store the exact model ID and vector dimension with every embedding batch. Do not mix vectors from different models or silent model revisions in one index.
/v1/rerankCatalog-declaredThe public catalog maps rerank-labelled models to /v1/rerank. Confirm the selected model’s document/query fields, maximum document count, score direction and response schema; test ranking order on a fixed fixture before production.
Generation and editing
/v1/images/generationsObserved/v1/images/editsCatalog-declaredcurl https://api.tokza.ai/v1/images/generations \
-H "Authorization: Bearer $TOKZA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "<IMAGE_MODEL_FROM_V1_MODELS>",
"prompt": "A clean isometric diagram of an API gateway",
"size": "1024x1024"
}'
Response format, size options, moderation, input images, masks, edit endpoints and URL expiry are model-specific. Download generated assets promptly and retain provider/model/request metadata needed for audits.
Speech
Catalog-declared Tokza’s public catalog included speech-to-text, text-to-speech, synchronous speech and asynchronous speech labels. Exact model, voice, file-size and format support must be confirmed per account.
/v1/audio/transcriptionsCatalog-declared/v1/audio/speechCatalog-declaredcurl https://api.tokza.ai/v1/audio/transcriptions \
-H "Authorization: Bearer $TOKZA_API_KEY" \
-F "model=<TRANSCRIPTION_MODEL_FROM_V1_MODELS>" \
-F "file=@meeting.mp3"
curl https://api.tokza.ai/v1/audio/speech \
-H "Authorization: Bearer $TOKZA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"<TTS_MODEL_FROM_V1_MODELS>","voice":"<SUPPORTED_VOICE>","input":"Hello from Tokza."}' \
--output speech.mp3
Do not log raw audio by default. Validate consent, voice rights, accepted formats, maximum duration and retention before uploading customer recordings.
Provider compatibility
Catalog-declared The public catalog included model-level anthropic and gemini labels. Those labels do not mean all Tokza models accept native provider SDKs or preserve every provider-specific field.
/v1/messagesAnthropic mapping/v1beta/models/{model}:generateContentGemini mapping| Before using a native format | Required check |
|---|---|
| Base URL and route | Use the catalog mapping only with a model declaring the matching endpoint type; confirm it in your authenticated account. |
| Model ID | Use the Tokza-visible ID, not an assumed upstream alias. |
| Headers and versions | Confirm whether provider-specific version headers are required or translated. |
| Streaming/events | Contract-test event types, terminal state, errors and usage fields. |
| Tools, caching and reasoning | Verify field preservation and billing behavior with a capped fixture. |
Long-running work
Conditional Video, music and some image/audio models use submit-and-poll workflows. Tokza’s catalog declares multiple media formats, but task paths, status values, callback signatures and cancellation rules vary by model family.
| Catalog family | Declared submission route | What remains model-specific |
|---|---|---|
| Unified video format | POST /v1/video/create | Payload, task state, status lookup and output schema. |
| OpenAI official video format | POST /v1/videos | Supported models, inputs, polling/events and edits. |
| Official video format | POST /v1/videos/generations | Accepted fields, task lifecycle and asset expiry. |
| Provider-specific media | Use the path paired with the model’s exact catalog label. | Every payload and lifecycle field; do not translate by name alone. |
Send the exact account-visible payload with an idempotency key if supported.
Store request ID, task ID, model, input hash, attempt and submitted time.
Use bounded backoff. Authenticate callbacks and reject replayed or stale events.
Confirm terminal status, output URLs, expiry, usage and balance before resubmitting.
Never assume a timeout means the task failed. A create request can complete upstream after your connection closes; query the known task or reconcile account usage before creating another.
Clients and tools
Any client that accepts an OpenAI-compatible base URL and bearer key can be evaluated with Tokza. Support still depends on the specific endpoints and fields that client uses.
Set base_url or baseURL to https://api.tokza.ai/v1. Start with Chat Completions unless the selected model declares Responses support.
Configure an OpenAI-compatible chat model with the Tokza base URL. Pin the model ID and test streaming, tools and usage metadata separately.
Configure the LLM and embedding clients independently; they may require different model IDs and capability labels.
For Cursor, OpenCode, Cline, n8n or similar tools, use their custom OpenAI-compatible provider option. Confirm whether the tool appends /v1 automatically.
TOKZA_API_KEY=<TOKZA_API_KEY>
OPENAI_API_BASE=https://api.tokza.ai/v1
OPENAI_BASE_URL=https://api.tokza.ai/v1
Reliability
Use the HTTP status and structured error type as the primary control signal. Preserve Tokza’s request identifier from errors and response headers when available; human-readable messages may be localized or change.
| Status | Meaning | Safe default |
|---|---|---|
400 | Malformed or unsupported request. | Do not retry unchanged. Fix fields/model/format. |
401 | Missing, invalid or revoked API key. | Do not retry. Verify secret source and rotation state. |
402 | Insufficient balance or billing restriction. | Stop. Review account balance and billing. |
403 | Key/account lacks permission for this route or model. | Stop. Check key scope and model entitlement. |
404 | Unknown route, model or task. | Stop. Refresh discovery and verify the task/account boundary. |
409 | Conflict or duplicate state. | Reconcile the existing task/request before resubmitting. |
422 | Semantically invalid payload. | Do not retry unchanged. Correct validation errors. |
429 | Rate limit or abuse protection. | Honor Retry-After; back off with jitter and reduce concurrency. |
500 | Internal failure. | Retry only transient, pre-execution-safe requests with a limit. |
502 | Upstream/gateway failure. | For billable or async creates, reconcile before retrying. |
503 | Temporarily unavailable or overloaded. | Back off, apply a retry budget and use an approved fallback. |
504 | Gateway timeout; execution state may be unknown. | Reconcile by request/task ID and usage before resubmitting. |
for attempt in range(4):
try:
return call_tokza()
except RateLimitError as error:
wait = error.retry_after or min(8, 2 ** attempt)
sleep(wait + random.uniform(0, 0.25))
except (BadRequestError, AuthenticationError, PermissionDeniedError):
raise
raise RuntimeError("Tokza retry budget exhausted")
Apply an end-to-end deadline shorter than your user-facing timeout. Do not stack SDK retries, proxy retries and application retries without one shared attempt budget.
Production checklist
/v1/moderationsCatalog-declaredTokza’s catalog maps a moderation capability to this route. Confirm which moderation model is available, the category/score schema and whether media is supported. Moderation is one control layer; keep application authorization, abuse monitoring and human escalation for consequential decisions.
Documentation evidence reviewed . Model availability and account contracts can change; authenticated discovery wins over this dated guide.