Chat Completions
POST /v1/chat/completions
為給定的聊天對話建立模型回應。相容於 OpenAI Chat Completions API。
請求主體
| 參數 | 類型 | 說明 |
|---|---|---|
model* | string | 要使用的模型 ID(例如 gpt-5.4、qwen3.5-flash、gemini-2.5-flash)。 |
messages* | array | 對話中的訊息清單。每一項都包含 role 與 content。 |
stream | boolean | 若為 true,則回傳 SSE 事件串流。預設值:false。 |
temperature | number | 取樣溫度 0–2。值越高 = 越隨機。預設值:1。 |
max_tokens | integer | 要產生的最大 token 數。上限取決於模型。 |
top_p | number | 核取樣機率。0–1。預設值:1。 |
stop | string[] | 最多 4 個序列,產生在遇到這些序列時停止。 |
n | integer | 要產生的補全選項數量。預設值:1。 |
範例請求
POST /v1/chat/completions
Authorization: Bearer YOUR_API_KEY
{
"model": "gpt-5.4-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7,
"max_tokens": 256
} 範例回應
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1714000000,
"model": "qwen3.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 26,
"completion_tokens": 9,
"total_tokens": 35
}
} 該端點會路由到閘道背後的所有供應商——選擇一個 model,在 model price comparison 中並排比較按 token 的價格。