TokenWorks

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:

  1. Register a TokenWorks account and log in to the dashboard
  2. Create an API Key in the dashboard
  3. 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:

text
https://www.token8341.com/v1

Chat Completions endpoint:

text
POST https://www.token8341.com/v1/chat/completions

Note: 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:

text
Authorization: Bearer sk-your-api-key-here

You 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 IDModel NameProvider
gpt-4oGPT-4oOpenAI
gpt-4o-miniGPT-4o MiniOpenAI
claude-3-5-sonnetClaude 3.5 SonnetAnthropic
claude-4-sonnetClaude 4 SonnetAnthropic
gemini-2-0-proGemini 2.0 ProGoogle
deepseek-v3DeepSeek-V3DeepSeek
qwen-maxQwen-MaxAlibaba Cloud

More models are being added continuously. Stay tuned for updates.

5Code Examples

curl

bash
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)

python
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)

javascript
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:

json
{
  "error": {
    "message": "Insufficient balance",
    "type": "insufficient_balance",
    "code": 402
  }
}
Status CodeNameDescription
400Bad Request请求参数错误,请检查请求体格式
401UnauthorizedAPI Key 无效或缺失,请检查 Authorization 请求头
402Insufficient Balance账户余额不足,请充值后重试
404Not Found请求的模型或接口不存在
429Rate Limit请求频率过高,请稍后重试
500Internal Server Error服务内部错误,请联系技术支持
503Service Unavailable模型服务暂时不可用,请稍后重试