跳转到主要内容

6.2 Chat Completions(OpenAI 兼容)

端点: POST /v1/chat/completions Base URL: https://api.tooken.ai

请求参数

参数类型必填描述
modelstring模型 ID,或 auto / auto-fast / auto-cheap
messagesarray对话消息列表
streamboolean是否流式返回,默认 false
max_tokensinteger最大输出 Token 数
temperaturenumber随机性,0-2,默认 1
toolsarray工具定义列表
tool_choicestring/object工具选择策略
平台扩展参数:
参数类型描述
route_strategyobjectAuto 路由策略配置
budget_limitnumber本次请求最大 Credits 上限
agent_walletstringAgent 钱包地址(用于 x402 结算)

请求示例

curl https://api.tooken.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "messages": [
      {"role": "system", "content": "你是一个专业的财务分析师。"},
      {"role": "user", "content": "分析这家公司的盈利能力"}
    ],
    "stream": false,
    "route_strategy": {
      "cost_weight": 0.6,
      "quality_weight": 0.4
    }
  }'

响应(非流式)

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1719000000,
  "model": "kimi-k2",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "从财务指标来看..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 150,
    "completion_tokens": 800,
    "total_tokens": 950
  },
  "platform": {
    "routed_model": "kimi-k2",
    "route_reason": "chinese-analysis-optimized",
    "credits_consumed": 0.475,
    "cost_saved_credits": 13.525
  }
}

流式响应(SSE)

curl https://api.tooken.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "auto", "messages": [...], "stream": true}'
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"从"},"index":0}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"财务"},"index":0}]}
...
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]