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模型上下文价格
deepseekDeepSeek——
local本地模型64K—
xiaomi小米 MiMo——

错误代码

代码消息说明
400Bad RequestInvalid request parameters
401UnauthorizedInvalid or expired API key
402Insufficient BalanceAccount balance too low
429Rate LimitedToo many requests per minute
500Server ErrorInternal server error, try again
503Model UnavailableModel temporarily unavailable