Documentation
Everything you need to integrate Tokenso into your application.
Introduction
Tokenso is an OpenAI-compatible API gateway.
Because the surface is identical to OpenAI's, migration consists of replacing one value:
import os
from openai import OpenAI
# before
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
base_url="https://api.openai.com/v1",
)
# after — nothing else changes
client = OpenAI(
api_key=os.environ["TOKENSO_API_KEY"],
base_url="https://api.tokenso.top/v1",
)
Nothing else changes.
Quickstart
1. Generate an API key in the console.
2. Install the OpenAI SDK.
pip install openai
3. Send a request.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENSO_API_KEY"],
base_url="https://api.tokenso.top/v1",
)
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
Authentication
Authenticate every request with a Bearer token.
curl https://api.tokenso.top/v1/models \
-H "Authorization: Bearer $TOKENSO_API_KEY"
Keys can be scoped, capped and revoked.
Base URL & routing
All requests go to a single host.
Routing behaviour:
- The nearest healthy edge node terminates TLS.
- The model identifier is mapped to a provider and region.
- Failures retry on a secondary upstream.
- Streaming responses are piped back without buffering.
https://api.tokenso.top/v1.Chat completions
The primary endpoint.
curl https://api.tokenso.top/v1/chat/completions \
-H "Authorization: Bearer $TOKENSO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "What is a token?"}
],
"temperature": 0.7,
"max_tokens": 512
}'
Request body
| Field | Type | Description |
|---|---|---|
| modelrequired | string | Model identifier. |
| messagesrequired | array | Array of message objects. |
| temperatureoptional | number | Sampling temperature, 0–2. |
| max_tokensoptional | integer | Upper bound on generated tokens. |
| streamoptional | boolean | When true, tokens stream over SSE. |
| toolsoptional | array | Function definitions for tool calling. |
Response
{
"id": "chatcmpl-9xK2mQ7fLp",
"object": "chat.completion",
"created": 1762387200,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A token is the smallest unit of text a model processes."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 118,
"total_tokens": 142
}
}
Returns a standard completion object.
Streaming
Set stream: true to receive server-sent events.
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a haiku about latency."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
Deltas may be split mid-token.
List models
Returns every model identifier available to your key.
curl https://api.tokenso.top/v1/models \
-H "Authorization: Bearer $TOKENSO_API_KEY"
{
"object": "list",
"data": [
{
"id": "gpt-4o",
"object": "model",
"owned_by": "openai",
"context_window": 128000
},
{
"id": "claude-sonnet-4",
"object": "model",
"owned_by": "anthropic",
"context_window": 200000
}
]
}
SDK examples
Every official OpenAI SDK works.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENSO_API_KEY"],
base_url="https://api.tokenso.top/v1",
)
resp = client.chat.completions.create(
model="claude-sonnet-4",
messages=[
{"role": "system", "content": "You are a senior backend engineer."},
{"role": "user", "content": "Summarise the CAP theorem in 2 lines."},
],
)
print(resp.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.TOKENSO_API_KEY,
baseURL: "https://api.tokenso.top/v1",
});
const resp = await client.chat.completions.create({
model: "gemini-2.5-flash",
messages: [{ role: "user", content: "Summarise the CAP theorem." }],
});
console.log(resp.choices[0].message.content);
curl https://api.tokenso.top/v1/chat/completions \
-H "Authorization: Bearer $TOKENSO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Summarise the CAP theorem."}]
}'
Errors & rate limits
Error responses mirror OpenAI's schema.
| Status | Type | Meaning |
|---|---|---|
| 400 | invalid_request_error | Malformed request body. |
| 401 | authentication_error | Missing or revoked key. |
| 402 | insufficient_quota | Insufficient balance. |
| 404 | model_not_found | Unknown model identifier. |
| 429 | rate_limit_exceeded | Rate limit exceeded. |
| 503 | upstream_unavailable | All upstreams failed. |
FAQ
Yes for chat completions.
Only with a restricted key.
Caching is applied at the upstream level.
Replace the base URL and API key.