Chat Completions API
向 /v1/chat/completions 发送兼容 OpenAI 的消息内容,模型标识应来自 /v1/models。
步骤
- 获取当前模型列表,不要硬编码提供商模型。
- 按顺序发送
messages,并提供非空model。 - 从
choices读取回复,从usage读取计量数据。 - 请求失败时保留
x-request-id。
示例
curl https://api.foxora.ai/v1/chat/completions \
-H "Authorization: Bearer $FOXORA_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "<model-id-from-v1-models>",
"messages": [
{"role": "user", "content": "Summarize this in three bullets."}
]
}'预期结果
HTTP 成功响应包含助手回复和此次请求的用量信息。
注意: 只有当客户端能处理 SSE 事件和提前中断的流时,才设置 stream: true。