Chat Completions
POST https://cpa.momoyai.com/v1/chat/completions| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | 从 /v1/models 返回中选择模型 ID。 |
messages |
array | 是 | 按顺序提供对话消息。 |
stream |
boolean | 否 | 为 true 时返回服务端事件流。 |
temperature |
number | 否 | 若目标模型支持,可调整输出随机性。 |
curl https://cpa.momoyai.com/v1/chat/completions \ -H "Authorization: Bearer $MOMOYAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.4", "messages": [ {"role": "system", "content": "回答应简洁准确。"}, {"role": "user", "content": "什么是幂等性?"} ] }'读取第一条文本响应时,先安全检查数组元素:
const content = response.choices[0]?.message.content ?? "";将 stream 设置为 true。客户端应逐条消费 Server-Sent Events,并在用户取消、网络中断或超时时关闭连接。参见流式响应。