OpenAI SDK 完全兼容 · 一行代码切换 · 30 秒接入
# 安装 OpenAI SDK pip install openai # 切换到 TOENK from openai import OpenAI client = OpenAI( base_url="https://toenk-api.com/v1", api_key="sk-your-api-key" ) response = client.chat.completions.create( model="deepseek-v4-flash", messages=[ {"role": "system", "content": "你是AI助手"}, {"role": "user", "content": "你好!"} ] ) print(response.choices[0].message.content)
所有 API 请求需在 HTTP Header 中携带 API Key:
Authorization: Bearer sk-your-api-key
获取 API Key:前往 控制台登录 → 创建 API 密钥。
⚠️ Key 格式为 48 位字符串,不需要 sk- 前缀。
POST https://toenk-api.com/v1/chat/completions
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | ✅ | 模型 ID,如 deepseek-v4-flash |
| messages | array | ✅ | 对话消息数组,含 role 和 content |
| temperature | number | — | 0-2,越高越随机,默认 0.7 |
| max_tokens | integer | — | 最大生成 token 数 |
| stream | boolean | — | 启用流式输出,默认 false |
| top_p | number | — | 核采样,默认 1 |
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "deepseek-v4-flash",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么可以帮你的?"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 9,
"total_tokens": 24
}
}
GET https://toenk-api.com/v1/models
curl https://toenk-api.com/v1/models \
-H "Authorization: Bearer sk-your-key"
查看模型广场了解可用模型和价格。
stream = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role":"user","content":"讲个故事"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
| 状态码 | 说明 |
|---|---|
| 400 | 请求参数错误 |
| 401 | API Key 无效或缺失 |
| 429 | 速率限制,请稍后重试 |
| 500 | 服务内部错误,联系技术支持 |
| 503 | 模型暂不可用,渠道维护中 |
以下 SDK 原生支持 TOENK API(设置 base_url 即可):