Chat Completions API
发送 OpenAI 相容消息;所选模型支持时可使用串流、工具、图像或结构化输出。
POST /v1/chat/completions
AuthorizationBearer $CHUA_API_KEYContent-Typeapplication/jsonfor request bodiesIdempotency-Key- 1–160 characters from
A-Z a-z 0-9 . _ : -; required for generation requests. X-CHUA-Request-ID- Save this response header as the request receipt when returned.
{"model":"YOUR_ALLOWED_MODEL","messages":[{"role":"user","content":"Hello"}],"max_tokens":256,"stream":false}请求字段
model- 必填字符串,1–255 个字符,且必须对密钥可见。
messages- 必填数组,1–128 项。角色支持 system、developer、user、assistant、tool;字符串内容最多 500,000 字符。
max_tokens- 必填整数,1–131,072,且不得超过所选模型限制。
stream- 布尔值,默认 false;模型必须已验证支持串流。
temperature / top_ptemperature0–2;top_p0–1. 受模型能力约束。tools- 最多 64 个函数工具;函数名最多 100 个字符。
response_formatjson_object或json_schema; 受模型能力约束。
响应
非串流响应包含 choices、model 和已计量 usage。串流使用 SSE,并以 data: [DONE] 结束。