TokenX Gateway documentation
An OpenAI-compatible API in front of Claude, GPT, Gemini and open models. If your code talks to the OpenAI Chat Completions API, it already talks to TokenX.
https://api.xtoken.com.au/v1 · Keys start with xtk_ · All requests are HTTPS and JSON.Quick start
- Request a key at [email protected]. You receive an
xtk_key; paste it into the usage dashboard to see spend, limits and try requests. - Set the base URL and key in your existing OpenAI client.
- Pick a model id from the model list.
curl https://api.xtoken.com.au/v1/chat/completions \
-H "Authorization: Bearer $XTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-haiku-4.5",
"messages": [{"role": "user", "content": "Say hello in one sentence."}],
"max_tokens": 64
}'
Authentication
Send your key as a bearer token: Authorization: Bearer xtk_.... Keys are scoped to an organisation, can be rotated or revoked at any time from the dashboard, and carry their own rate limit and monthly spend cap. Treat keys as secrets: load them from environment variables or a secret manager, never commit them to source control or ship them in client-side code.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/chat/completions | Chat completion. OpenAI request and response schema; supports stream: true. |
| GET | /v1/models | Models available to your key, in OpenAI list format. |
| GET | /v1/usage | Token and cost totals for the current billing period, per model and per key. |
| GET | /health | Gateway liveness. Returns {"ok": true}. |
Models & routing
The model field accepts a TokenX model id (recommended) or a raw upstream id. TokenX ids are stable aliases such as claude-sonnet-4.6; when a provider releases a dated revision we update the alias and announce it in the changelog, so your code keeps working. Raw ids such as us.anthropic.claude-sonnet-4-6 pin an exact upstream version.
Each request is fulfilled by exactly one provider: Anthropic, Meta, DeepSeek, Qwen and Amazon models via AWS Bedrock; OpenAI models via Azure AI Foundry; Gemini via Google Vertex AI. Responses include the upstream model id in the model field so you always know what served the request.
Current list: /models. Programmatic list: GET /v1/models.
Streaming
Set "stream": true to receive server-sent events in the OpenAI chat.completion.chunk format, terminated by data: [DONE]. Streaming works identically across providers; token usage is sent in the final chunk.
stream = client.chat.completions.create(
model="gemini-3-flash", stream=True,
messages=[{"role": "user", "content": "Write a haiku about Sydney Harbour."}],
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Parameters
| Parameter | Support | Notes |
|---|---|---|
messages | all | system, user, assistant roles. Image content parts supported on vision-capable models. |
max_tokens | all | Mapped to the provider's output limit. Also accepts max_completion_tokens. |
temperature, top_p | all | Passed through. Some reasoning models ignore temperature. |
stop | all | Up to 4 sequences. |
tools, tool_choice | Claude, GPT, Gemini, Nova | OpenAI function-calling schema, translated per provider. Returned as tool_calls. |
response_format | GPT, Gemini | json_object and json_schema. |
user | all | Opaque end-user id, stored with usage records for your reporting. Do not send personal data. |
Errors
Errors use the OpenAI error envelope: {"error": {"message": "...", "type": "...", "code": "..."}}.
| HTTP | Meaning | What to do |
|---|---|---|
| 400 | Invalid request | Check the message against the schema above; the body says which field. |
| 401 | Missing or invalid key | Check the Authorization header. Revoked keys return 401. |
| 403 | Model not enabled for this key | Ask us to enable it, or pick another model from GET /v1/models. |
| 404 | Unknown model id | See /models. |
| 429 | Rate limit or spend cap reached | Back off using Retry-After. Caps are adjustable; contact us. |
| 502 / 503 | Upstream provider error or overload | Retry with exponential backoff; consider a fallback model. |
Rate limits
Limits are per key, in tokens per minute (TPM) and requests per minute (RPM), and are returned on every response in x-ratelimit-limit-tokens, x-ratelimit-remaining-tokens, x-ratelimit-limit-requests and x-ratelimit-remaining-requests. Starter keys begin at 200K TPM / 200 RPM; higher limits are set with you based on your workload.
Data residency
By default requests are routed to the provider region with the best availability for the chosen model (United States for most frontier models). Keys can be pinned to the au tier, which restricts inference to Sydney (AWS ap-southeast-2 and Azure australiaeast) and only exposes models available there. Request content is processed in memory and is not stored by TokenX; metadata (timestamps, token counts, model, status, your user field) is retained for billing and support for 90 days. See Security.
Usage & billing
Billing is per token at the rates on the pricing page, in USD, invoiced monthly in arrears for approved accounts or drawn from prepaid credit. GET /v1/usage and the dashboard show spend by model and key. Every response carries usage.prompt_tokens, usage.completion_tokens and usage.total_tokens as reported by the provider.
SDK examples
Python
from openai import OpenAI
client = OpenAI(base_url="https://api.xtoken.com.au/v1", api_key=os.environ["XTOKEN_API_KEY"])
r = client.chat.completions.create(model="gpt-5-mini", messages=[{"role": "user", "content": "Hi"}])
Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.xtoken.com.au/v1", apiKey: process.env.XTOKEN_API_KEY });
const r = await client.chat.completions.create({ model: "claude-opus-4.6", messages: [{ role: "user", content: "Hi" }] });
LangChain
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="deepseek-v3.2", base_url="https://api.xtoken.com.au/v1", api_key=os.environ["XTOKEN_API_KEY"])
Anything that accepts an OpenAI base URL — Vercel AI SDK, LiteLLM, Continue, Cursor, Open WebUI — works the same way.