API Documentation
Detailed integration guide and API reference to help you quickly integrate the TokenWorks LLM API and AI gateway
1Quick Start
Start using the TokenWorks API in three simple steps:
- Register a TokenWorks account and log in to the dashboard
- Create an API Key in the dashboard
- Use your API Key to call our endpoints
Tip: New users receive free trial credits upon registration — no credit card required.
2Base URL
The API base URL is below. All requests use HTTPS:
https://www.token8341.com/v1Chat Completions endpoint:
POST https://www.token8341.com/v1/chat/completionsNote: This endpoint is fully compatible with the OpenAI Chat Completions API format. You can directly use the OpenAI SDK.
3Authentication
TokenWorks uses Bearer Token authentication. Include your API Key in the request header:
Authorization: Bearer sk-your-api-key-hereYou can create and manage your keys in the 'API Keys' section of the dashboard. Never expose your API Key in public repositories or client-side code.
4Supported Models
| Model ID | Model Name | Provider |
|---|---|---|
| gpt-4o | GPT-4o | OpenAI |
| gpt-4o-mini | GPT-4o Mini | OpenAI |
| claude-3-5-sonnet | Claude 3.5 Sonnet | Anthropic |
| claude-4-sonnet | Claude 4 Sonnet | Anthropic |
| gemini-2-0-pro | Gemini 2.0 Pro | |
| deepseek-v3 | DeepSeek-V3 | DeepSeek |
| qwen-max | Qwen-Max | Alibaba Cloud |
More models are being added continuously. Stay tuned for updates.
5Code Examples
curl
curl https://www.token8341.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key-here" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'Python (openai SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://www.token8341.com/v1",
api_key="sk-your-api-key-here"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)Node.js (openai SDK)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://www.token8341.com/v1",
apiKey: "sk-your-api-key-here",
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "user", content: "Hello!" },
],
});
console.log(response.choices[0].message.content);6Error Codes
When an API request fails, the following HTTP status codes and error information are returned:
{
"error": {
"message": "Insufficient balance",
"type": "insufficient_balance",
"code": 402
}
}| Status Code | Name | Description |
|---|---|---|
| 400 | Bad Request | 请求参数错误,请检查请求体格式 |
| 401 | Unauthorized | API Key 无效或缺失,请检查 Authorization 请求头 |
| 402 | Insufficient Balance | 账户余额不足,请充值后重试 |
| 404 | Not Found | 请求的模型或接口不存在 |
| 429 | Rate Limit | 请求频率过高,请稍后重试 |
| 500 | Internal Server Error | 服务内部错误,请联系技术支持 |
| 503 | Service Unavailable | 模型服务暂时不可用,请稍后重试 |