OpenAI-compatible API for China's best AI models
TokenOutput is a drop-in replacement for the OpenAI API. Just change the base URL and model name.
curl https://token-output.klk1129635667.workers.dev/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'
All API requests require an API key sent in the Authorization header.
Authorization: Bearer sk-your-api-key
Get your API key from the dashboard.
/v1/chat/completions
Creates a chat completion. Fully compatible with the OpenAI Chat Completions API.
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID (e.g. deepseek-chat) |
| messages | array | Yes | Array of message objects |
| stream | boolean | No | Enable SSE streaming (default: false) |
| temperature | number | No | Sampling temperature (0-2) |
| max_tokens | integer | No | Max tokens to generate |
| top_p | number | No | Nucleus sampling |
| stop | string|array | No | Stop sequences |
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"total_tokens": 30
}
}
Set "stream": true to receive Server-Sent Events (SSE).
curl https://token-output.klk1129635667.workers.dev/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"model": "deepseek-chat", "stream": true,
"messages": [{"role": "user", "content": "Hello!"}]}'
/v1/models
| Model ID | Provider | Best for |
|---|---|---|
| deepseek-chat | DeepSeek | General purpose, coding |
| deepseek-reasoner | DeepSeek | Complex reasoning, math |
| qwen-turbo | Alibaba | Fast, low cost |
| qwen-plus | Alibaba | Balanced quality/cost |
| qwen-max | Alibaba | Highest quality |
| qwen-long | Alibaba | Long documents |
| glm-4-plus | Zhipu AI | Flagship, best quality |
| glm-4-air | Zhipu AI | Balanced |
| glm-4-flash | Zhipu AI | Ultra fast, cheapest |
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://token-output.klk1129635667.workers.dev/v1"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://token-output.klk1129635667.workers.dev/v1',
});
const response = await client.chat.completions.create({
model: 'deepseek-chat',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' },
],
});
console.log(response.choices[0].message.content);
stream = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Write a poem"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
/v1/billing/balance
curl https://token-output.klk1129635667.workers.dev/v1/billing/balance \
-H "Authorization: Bearer sk-your-api-key"
# Response: {"balance": 9.50}
Top up your balance from the dashboard, or create a checkout session via API:
/v1/billing/checkout
curl -X POST https://token-output.klk1129635667.workers.dev/v1/billing/checkout \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"amount": 10}'
# Response: {"url": "https://checkout.stripe.com/...", "session_id": "cs_..."}
| Code | Meaning |
|---|---|
| 400 | Bad request — invalid model or missing fields |
| 401 | Unauthorized — invalid or missing API key |
| 402 | Insufficient balance — top up your account |
| 429 | Rate limited — slow down requests |
| 502 | Upstream provider error |