聊天補全
相容 OpenAI 的聊天補全,支援串流、圖片、工具呼叫和推理控制。
POST /v1/chat/completions
curl https://api.unquant.io/v1/chat/completions \
-H "Authorization: Bearer $UNQUANT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"glm-5.3-flash",
"messages":[{"role":"user","content":"Hello!"}]}'請求欄位
modelstringRequiredglm-5.3-flash 或 qwen-3.8-flash-next 或 deepseek-v4.1-flash-1017。
messagesarrayRequired角色包括 system、user、assistant 和 tool。內容可以是字串,或由 text 和 image_url 組成的陣列。
streamboolean以 server-sent events 串流方式傳送回覆。
stream_optionsobject{"include_usage": true} 會在最後一個資料塊附加 token 計數。
max_tokensinteger回覆長度的上限。
max_completion_tokensinteger與 max_tokens 相同。
temperaturenumber取樣的隨機程度。
top_pnumber核取樣。
top_kinteger從機率最高的 k 個 token 中取樣。
min_pnumbertoken 的最小相對機率。
seedinteger可重現取樣的隨機種子。
stopstring or array停止序列。
frequency_penaltynumber依 token 出現頻率進行懲罰。
presence_penaltynumber對出現過的 token 進行懲罰。
repetition_penaltynumber乘法式重複懲罰。
toolsarray模型可呼叫的函數,使用 OpenAI 格式。
tool_choicestring or objectauto、none、required 或指定的函數名稱。
parallel_tool_callsboolean允許在同一輪中進行多個工具呼叫。
response_formatobjectJSON 輸出。
logprobsboolean回傳 token 對數機率。
top_logprobsinteger每個 token 要回傳多少個替代選項。
ninteger必須為 1:每次請求只有一個補全。
reasoning_effortstring所有模型:low 或 high;GLM-5.3-Flash 和 DeepSeek V4.1 Flash 1017 也支援 max。Qwen 3.8 Flash Next 和 DeepSeek V4.1 Flash 1017 也支援 none(關閉思考);GLM-5.3-Flash 永遠思考,不接受此設定。
chat_template_kwargsobject範本開關,例如 {"enable_thinking": false}(Qwen 3.8 Flash Next 和 DeepSeek V4.1 Flash 1017;GLM-5.3-Flash 永遠思考)。
prompt_cache_keystring每個對話使用同一個穩定值,可讓該對話的輪次保留在持有其快取提示詞的伺服器上。若未設定,系統根據系統提示詞和第一則訊息識別對話,因此若你的系統提示詞在輪次之間有所變動,請設定此值。
其他欄位會被忽略。
回應
response.choices[0].message.content使用量計數是為了你自己的監控而回傳的;從不計費。
串流
設定 "stream": true 後,回覆會以 OpenAI 資料塊格式透過 server-sent events 傳送,並以 data: [DONE] 結尾。從 choices[0].delta.content 讀取文字。
圖片
每個模型都接受以 base64 資料 URL(data:image/png;base64,...、JPEG 或 WebP)形式傳遞的 image_url 圖片。透過 URL 連結的圖片不會被擷取,會回傳 400 錯誤。
{"role": "user", "content": [
{"type": "text", "text": "Describe this image."},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}
]}工具呼叫
依照 OpenAI API 的方式傳入 tools。當模型呼叫工具時,回覆的 finish_reason: "tool_calls",並含有 message.tool_calls;執行工具後,附上帶有結果和對應 tool_call_id 的 tool 訊息,再次呼叫。
推理
每個模型在回答前都會先推理,並接受 reasoning_effort:low 適合輕度推理,high 適合較難的問題;GLM-5.3-Flash 和 DeepSeek V4.1 Flash 1017 也有 max,預設為 high。思考內容單獨回傳於 reasoning_content,不會混入 content。
GLM-5.3-Flash 永遠思考:無法關閉其推理,要求關閉的請求會以 400 錯誤被拒絕。Qwen 3.8 Flash Next 和 DeepSeek V4.1 Flash 1017 也可以直接回答:傳送 none,或 "thinking": {"type": "disabled"},或 "chat_template_kwargs": {"enable_thinking": false}。
並行
你的方案決定所有金鑰同時可執行的請求數。超出該限制的請求會立即回傳 429,不會排隊等待;進行中的請求不受影響。