对话(文本)

对话补全,支持流式或非流式,支持或不支持工具调用。

请求

http
POST /v1/chat/completions
json
{
  "messages": [
    { "role": "user", "content": "Explique le routage IA en une phrase." }
  ],
  "model": null,
  "routing_strategy": "auto",
  "max_tokens": null,
  "temperature": null,
  "stream": false,
  "tools": null,
  "tool_choice": null
}

只有 messages 是必填项。modelrouting_strategy 的说明请参阅路由与故障转移

响应

json
{
  "content": "Le routage IA choisit automatiquement le meilleur fournisseur disponible pour chaque appel.",
  "finish_reason": "stop",
  "model": "claude-opus-5",
  "provider": "anthropic",
  "input_tokens": 12,
  "output_tokens": 18,
  "tool_calls": null
}

流式输出

传入 "stream": true 即可以 Server-Sent Events 格式接收响应,而不是单一的 JSON 数据块。

typescript
for await (const chunk of client.chat.completions.stream({
  messages: [{ role: "user", content: "Compte jusqu'a 10." }],
})) {
  process.stdout.write(chunk.delta);
}

工具调用(Function Calling)

提供 tools(标准 JSON Schema 格式的定义),模型可以用 tool_calls 代替(或补充)文本进行响应。将结果放入角色为 "tool" 的消息中,并附上对应的 tool_call_id,以继续对话。

json
{
  "messages": [
    { "role": "user", "content": "Quel temps fait-il a Paris ?" },
    {
      "role": "assistant",
      "content": "",
      "tool_calls": [
        { "id": "call_1", "name": "get_weather", "arguments": { "city": "Paris" } }
      ]
    },
    { "role": "tool", "tool_call_id": "call_1", "content": "18C, nuageux" }
  ],
  "tools": [
    {
      "name": "get_weather",
      "description": "Meteo actuelle d'une ville.",
      "parameters": {
        "type": "object",
        "properties": { "city": { "type": "string" } },
        "required": ["city"]
      }
    }
  ]
}
如需自动化的多轮编排(服务器在每次工具结果后重新调用模型,并保留长期记忆),请参阅 AI 智能体 指南,而不是自行管理该循环。

兼容模型

Anthropic(Claude)、OpenAI(GPT)、Google(Gemini)、DeepSeek、xAI(Grok)、Mistral、Moonshot、MiniMax、Meta——确切且最新的列表可通过目录查询获得:

bash
GET /v1/models?category=text