API 文档
Base URL: https://tokenhub.eric-ai.cn
快速开始
1
获取 API Key
注册账号后,在控制台的「API 密钥」页创建一把 Key。
2
设置 API Key
把 Key 设为环境变量,或在请求头 Authorization 中传入(Bearer <key>)。
3
发起请求
向 /v1/chat/completions 发送 POST 请求,指定 model 与 messages 即可。
代码示例
cURL
curl https://tokenhub.eric-ai.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H t('topup.bearerExample', locale) \
-d '{
"model": "auto",
"messages": [{"role": "user", "content": "Hello!"}]
}'Python
import requests
api_key = t('topup.creditsExample', locale)
url = "https://tokenhub.eric-ai.cn/v1/chat/completions"
resp = requests.post(
url,
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
json={
"model": "auto",
"messages": [
{"role": "user",
"content": "Hello!"}
],
},
)
print(resp.json())JavaScript
const apiKey = t('topup.creditsExample', locale);
const resp = await fetch(
"https://tokenhub.eric-ai.cn/v1/chat/completions",
{
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "auto",
messages: [
{ role: "user",
content: "Hello!" }
],
}),
}
);
const data = await resp.json();可用模型
| 模型 ID | 模型 | 上下文 | 价格 |
|---|---|---|---|
| deepseek | DeepSeek | — | — |
| local | 本地模型 | 64K | — |
| xiaomi | 小米 MiMo | — | — |
错误代码
| 代码 | 消息 | 说明 |
|---|---|---|
| 400 | Bad Request | Invalid request parameters |
| 401 | Unauthorized | Invalid or expired API key |
| 402 | Insufficient Balance | Account balance too low |
| 429 | Rate Limited | Too many requests per minute |
| 500 | Server Error | Internal server error, try again |
| 503 | Model Unavailable | Model temporarily unavailable |