建立聊天完成

根據對話記錄建立模型回應。支援串流與非串流回應。 相容於 OpenAI Chat Completions API。

POST /v1/chat/completions

服務根位址: https://getrouter.ai

通訊協定: OpenAI Chat Completions

驗證: Authorization: Bearer YOUR_API_KEY

請求主體

請求主體為必填。 媒體類型: application/json

請求欄位

欄位型別必填說明
modelstring要使用的模型 ID
messagesarray<object>對話訊息清單
temperaturenumber取樣溫度 預設值: 1; 範圍: 0–2
top_pnumber核心取樣參數 預設值: 1; 範圍: 0–1
ninteger產生數量 預設值: 1; 範圍: 1–∞
streamboolean是否使用串流回應 預設值: false
stream_optionsobject
stopstring or array<string>用於停止生成的序列
max_tokensinteger最大產生 Token 數
max_completion_tokensinteger最大完成 Token 數
presence_penaltynumber預設值: 0; 範圍: -2–2
frequency_penaltynumber預設值: 0; 範圍: -2–2
logit_biasobject
userstring
toolsarray<object>
tool_choicestring or object
response_formatobject
seedinteger
reasoning_effortstring推理強度(用於支援推理的模型) 可選值: low, medium, high
modalitiesarray<string>
audioobject

請求範例

curl --request POST \
  --url https://getrouter.ai/v1/chat/completions \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "MODEL_ID",
  "messages": [
    {
      "role": "system",
      "content": "你好,請介紹一下自己。"
    }
  ],
  "stream": false,
  "temperature": 1,
  "max_tokens": 1
}'

回應

狀態碼說明
200已成功建立回應
400請求參數錯誤
429請求頻率受限

成功回應欄位

欄位型別必填說明
idstring
objectstring
createdinteger
modelstring
choicesarray<object>
usageobject
system_fingerprintstring

回應範例

{
  "id": "string",
  "object": "object",
  "created": 1,
  "model": "MODEL_ID",
  "choices": [
    {
      "index": 1,
      "message": {
        "role": "system",
        "content": "你好,請介紹一下自己。",
        "name": "string",
        "tool_calls": [
          {
            "id": null,
            "type": null,
            "function": null
          }
        ],
        "tool_call_id": "string",
        "reasoning_content": "string"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1,
    "completion_tokens": 1,
    "total_tokens": 1,
    "prompt_tokens_details": {
      "cached_tokens": 1,
      "text_tokens": 1,
      "audio_tokens": 1,
      "image_tokens": 1
    },
    "completion_tokens_details": {
      "text_tokens": 1,
      "audio_tokens": 1,
      "reasoning_tokens": 1
    }
  },
  "system_fingerprint": "string"
}

相關指南

如需完整工作流程與範例,請閱讀 Chat Completions API 指南。


此頁面由公開 Relay OpenAPI 規格自動產生。完整規格請見 API Explorer