API 文档
词元智算提供标准化 AI 算力计量接口,帮助开发者透明化成本计算。所有接口返回 JSON 格式数据。
认证方式
// 所有 API 请求需要携带 API Key
Authorization: Bearer your_api_key_here
X-API-Key: your_api_key_here
Authorization: Bearer your_api_key_here
X-API-Key: your_api_key_here
计算任务成本
POST
/api/v1/cost/calculate
根据任务和模型计算预估成本和消耗。
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
| task_id | 必填 | 任务 ID(T1-T7) |
| model | 必填 | 模型标识 |
| language | 可选 | 语言(zh/en,默认 zh) |
响应示例
{
"success": true,
"data": {
"task": "代码生成",
"model": "DeepSeek-V3",
"tokens": 105,
"input_tokens": 20,
"output_tokens": 85,
"flops_t": 7.77,
"cost_usd": 0.000026,
"estimated_time_s": 1.05
}
}
"success": true,
"data": {
"task": "代码生成",
"model": "DeepSeek-V3",
"tokens": 105,
"input_tokens": 20,
"output_tokens": 85,
"flops_t": 7.77,
"cost_usd": 0.000026,
"estimated_time_s": 1.05
}
}
计算标准 Token
POST
/api/v1/st/calculate
根据输入输出 Token 数计算标准 Token 消耗。
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
| model | 必填 | 模型标识 |
| input_tokens | 必填 | 输入 Token 数 |
| output_tokens | 必填 | 输出 Token 数 |
响应示例
{
"success": true,
"data": {
"model": "GPT-4o",
"input_tokens": 1000,
"output_tokens": 500,
"total_tokens": 1500,
"flops_per_token_t": 3.6,
"total_flops_t": 5400,
"cost_usd": 0.00375
}
}
"success": true,
"data": {
"model": "GPT-4o",
"input_tokens": 1000,
"output_tokens": 500,
"total_tokens": 1500,
"flops_per_token_t": 3.6,
"total_flops_t": 5400,
"cost_usd": 0.00375
}
}
获取任务列表
GET
/api/v1/tasks
返回所有标准任务定义。
获取模型列表
GET
/api/v1/models
返回已计量的模型数据库。
模型对比
GET
/api/v1/compare
对比多个模型在同一任务上的消耗。
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
| task_id | string | 任务 ID |
| models | array | 模型列表 |
Token 市场(即将上线)
GET
/api/v1/market
BETA
获取 Token 实时市场价格和交易深度。
错误响应
{
"success": false,
"error": {
"code": "INVALID_MODEL",
"message": "Unknown model: xxx"
}
}
"success": false,
"error": {
"code": "INVALID_MODEL",
"message": "Unknown model: xxx"
}
}
SDK 和示例代码
Python
import requests
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
# 计算任务成本
response = requests.post(
"https://api.tokenx.ai/v1/cost/calculate",
headers=headers,
json={"task_id": "T3", "model": "deepseek-v3"}
)
print(response.json())
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
# 计算任务成本
response = requests.post(
"https://api.tokenx.ai/v1/cost/calculate",
headers=headers,
json={"task_id": "T3", "model": "deepseek-v3"}
)
print(response.json())