跳到正文

对话补全

POST /v1/chat/completions,支持 OpenAI 兼容的消息、工具与流式输出。

http
POST https://api.webway.sh/v1/chat/completions

将此端点用于 OpenAI SDK 以及使用 Chat Completions 协议的客户端。

请求

bash
curl https://api.webway.sh/v1/chat/completions \
  -H "Authorization: Bearer $WEBWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.6-terra",
    "messages": [{"role": "user", "content": "Say hello."}],
    "max_tokens": 128
  }'
字段 类型 说明
model string 必填,带提供商前缀的模型 ID
messages array 必填,systemuserassistant 消息
max_tokens integer 生成的最大 token 数
temperature number 采样温度
tools array OpenAI 兼容的函数定义
tool_choice string or object 控制工具的选择方式
stream boolean true 时以服务器发送事件流式返回

若所选模型支持提供商专有字段,这些字段会被透传。

响应

json
{
  "id": "chatcmpl_01…",
  "object": "chat.completion",
  "model": "openai/gpt-5.6-terra",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "Hello!"},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 9, "completion_tokens": 2, "total_tokens": 11}
}

stream: true 时,每一行 SSE data: 都包含一个 chat.completion.chunk;流以 data: [DONE] 结束。