TokenLab accepts four API formats: OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, and Gemini. You choose the format by the endpoint you call. No request header or response header switches it. Headers carry other things: your credentials, the delivery option, IDs for support and billing, and rate limit information. This guide lists the headers TokenLab documents, says which of them can be missing, and shows a client that reads them correctly.
The Endpoint Decides the Format
Each endpoint keeps the schema of its own API format:
- Chat Completions (
/v1/chat/completions) uses the OpenAI-compatible schema:choices,message.content, and ausageblock withprompt_tokens,completion_tokens, andtotal_tokens. - Responses (
/v1/responses) uses the OpenAI Responses format, with background responses, tools, and events. Use it only when the model listsopenai_responses. - Anthropic Messages (
/v1/messages) uses the native Anthropic schema, withcontentblocks, thinking, andusage.output_tokens. When you set up the Anthropic SDK, usehttps://api.tokenlab.shas the base URL, without/v1. - Gemini (
/v1beta/models/{model}:generateContent) accepts native Geminicontentsand parts and returns Gemini candidates.
A model does not necessarily accept all four formats. Before you route a request, call Get a Model (GET /v1/models/{model}, public, no key) and read tokenlab.accepted_request_formats. The API formats guide explains when to choose each format.
Request Headers
| Header | Use |
|---|---|
Authorization: Bearer sk-... |
Your API key for model requests. Management endpoints use a management token (mt-...) in the same header. Anthropic Messages also accepts x-api-key. Gemini also accepts x-goog-api-key or the key query parameter. |
Content-Type: application/json |
Required for POST requests with a JSON body |
X-TokenLab-Delivery-Policy |
auto, verified, or official. It overrides the API key setting for one request. An invalid value returns 400. See the delivery tiers guide. |
Idempotency-Key |
For the requests listed in Retry safely with an idempotency key. A retry with the same key and body does not run or charge the request twice. |
Response Headers
Use these headers when they are present. Some are not set on every response.
| Header | Meaning |
|---|---|
X-Request-ID |
The request identifier. Log it and send it to support. |
X-Routing-Time-MS |
Non-streaming: milliseconds until the upstream response arrived, including queueing and inference. Streaming: always 0. It is not a routing or queue measurement. |
X-Task-ID |
The public task ID of an async job, such as video, music, 3D, or a task-based image. It matches the task id. |
X-Billing-Transaction-ID |
The billing transaction, after final billing. It appears only when billing settled before the response was sent. |
For non-streaming OpenAI-compatible responses, the same value is also in the JSON body as billing_transaction_id. Gemini and other native formats may expose it only in the header. A streaming call can settle after the connection closes. When the ID is absent, read it from your usage records later. See the Billing and pricing guide.
Headers on a 429 response
When a request exceeds the limit of its API key, TokenLab returns 429 rate_limit_exceeded with four headers:
| Header | Meaning |
|---|---|
Retry-After |
Seconds to wait before the next request |
X-RateLimit-Limit |
Requests allowed per minute for this API key |
X-RateLimit-Remaining |
Requests left in the current window |
X-RateLimit-Reset |
Unix time in seconds when the window resets |
Use the Retry-After value for retries instead of a fixed backoff. Read the limit from X-RateLimit-Limit instead of assuming a copied table. Repeated failed authentication from one IP address is limited too. After about 20 failures in a minute the API returns 429 with a Retry-After header. Fix the key instead of retrying a 401. The Rate limits guide has the details.
Example: Capture the IDs and Retry on 429
This Python client sends a Chat Completions request, logs the request ID, reads the billing ID from the body or the header, and retries only on 429:
import os
import time
import requests
API_KEY = os.environ["TOKENLAB_API_KEY"]
URL = "https://api.tokenlab.sh/v1/chat/completions"
HEADERS = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
PAYLOAD = {
"model": "gpt-5.6-terra",
"messages": [{"role": "user", "content": "Summarize system status."}],
}
for attempt in range(3):
response = requests.post(URL, headers=HEADERS, json=PAYLOAD, timeout=30)
request_id = response.headers.get("X-Request-ID") # log it for support
if response.status_code == 200:
data = response.json()
# Present only when billing settled before the response was sent.
billing_id = data.get("billing_transaction_id") or response.headers.get(
"X-Billing-Transaction-ID"
)
print(f"request_id={request_id} billing_transaction_id={billing_id}")
print(data["choices"][0]["message"]["content"])
break
if response.status_code == 429:
wait = float(response.headers.get("Retry-After", 2 ** attempt))
print(
f"request_id={request_id} rate limited: "
f"limit={response.headers.get('X-RateLimit-Limit')}/min, "
f"remaining={response.headers.get('X-RateLimit-Remaining')}, "
f"resets at Unix time {response.headers.get('X-RateLimit-Reset')}"
)
time.sleep(wait)
continue
response.raise_for_status()
else:
raise RuntimeError("Still rate limited after 3 attempts")
Both IDs can be None. The request ID is the main key for support. The billing ID is a convenience that can arrive later through usage records.
What to Log
- Keep
X-Request-ID, the billing transaction ID when present, andX-Task-IDfor async jobs, with the status code and latency. - Never log
Authorizationheaders, API keys, management tokens, or private signed URLs. - For server-side reconciliation, use
GET /v1/management/api-keys/{keyId}/usageinstead of scraping dashboard pages or estimating from token counts. See Logs and troubleshooting.
Sources
- TokenLab docs: API ReferenceSources checked 2026-11-11
- TokenLab docs: Get a ModelSources checked 2026-11-11
- TokenLab docs: API formatsSources checked 2026-11-11
- TokenLab docs: Rate limitsSources checked 2026-11-11
- TokenLab docs: Billing and pricingSources checked 2026-11-11
- TokenLab docs: Handle API errorsSources checked 2026-11-11
- TokenLab docs: Logs and troubleshootingSources checked 2026-11-11



