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] 結束。