建立對話補全
post/v1/chat/completions
根據對話歷史建立模型回應。串流與非串流回應皆支援。
相容於 OpenAI Chat Completions API。
驗證
把 OLETOKEN 的 API Key 作為 Bearer Token 放進 Authorization 請求標頭。金鑰在控制台的「API 金鑰」頁建立。
Authorization: Bearer $OLETOKEN_API_KEY請求主體
Content-Type:application/json
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
| model | string | 模型 ID | |
| messages | Message[] | 對話訊息 | |
| role | stringsystemuserassistanttooldeveloper | 訊息角色 | |
| content | string | MessageContent[] | 訊息內容 | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | 圖片 URL 或 Base64 資料 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | Base64 編碼的音訊資料 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | 傳送者名稱 |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | 工具呼叫 ID(用於角色為 tool 的訊息) |
| reasoning_content | string | — | 推理內容 |
| temperature | number0–2default: 1 | — | 取樣溫度 |
| top_p | number0–1default: 1 | — | 核心取樣參數 |
| n | integer≥ 1default: 1 | — | 要生成的補全數量 |
| stream | booleandefault: false | — | 是否以串流方式回傳回應 |
| stream_options | object | — | — |
| include_usage | boolean | — | — |
| stop | string | string[] | — | 停止序列 |
| max_tokens | integer | — | 生成的 Token 數量上限 |
| max_completion_tokens | integer | — | 補全 Token 數量上限 |
| presence_penalty | number-2–2default: 0 | — | — |
| frequency_penalty | number-2–2default: 0 | — | — |
| logit_bias | object | — | — |
| user | string | — | — |
| tools | Tool[] | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| description | string | — | — |
| parameters | object | — | JSON Schema 格式的參數定義 |
| tool_choice | string | objectnoneautorequired | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| response_format | ResponseFormat | — | — |
| type | stringtextjson_objectjson_schema | — | — |
| json_schema | object | — | JSON Schema 定義 |
| seed | integer | — | — |
| reasoning_effort | stringlowmediumhigh | — | 推理強度(適用於支援推理的模型) |
| modalities | string[] | — | — |
| audio | object | — | — |
| voice | string | — | — |
| format | string | — | — |
回應
200已建立回應
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
| id | string | — | — |
| object | string | — | — |
| created | integer | — | — |
| model | string | — | — |
| choices | object[] | — | — |
| index | integer | — | — |
| message | Message | — | — |
| role | stringsystemuserassistanttooldeveloper | 訊息角色 | |
| content | string | MessageContent[] | 訊息內容 | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | 圖片 URL 或 Base64 資料 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | Base64 編碼的音訊資料 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | 傳送者名稱 |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | 工具呼叫 ID(用於角色為 tool 的訊息) |
| reasoning_content | string | — | 推理內容 |
| finish_reason | stringstoplengthtool_callscontent_filter | — | — |
| usage | Usage | — | — |
| prompt_tokens | integer | — | Prompt Token 數量 |
| completion_tokens | integer | — | 補全 Token 數量 |
| total_tokens | integer | — | Token 總數 |
| prompt_tokens_details | object | — | — |
| cached_tokens | integer | — | — |
| text_tokens | integer | — | — |
| audio_tokens | integer | — | — |
| image_tokens | integer | — | — |
| completion_tokens_details | object | — | — |
| text_tokens | integer | — | — |
| audio_tokens | integer | — | — |
| reasoning_tokens | integer | — | — |
| system_fingerprint | string | — | — |
400請求參數無效
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
| error | object | — | — |
| message | string | — | 錯誤訊息 |
| type | string | — | 錯誤類型 |
| param | string | null | — | 相關的參數 |
| code | string | null | — | 錯誤代碼 |
429超過速率限制
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
| error | object | — | — |
| message | string | — | 錯誤訊息 |
| type | string | — | 錯誤類型 |
| param | string | null | — | 相關的參數 |
| code | string | null | — | 錯誤代碼 |
請求範例
curl -X POST 'https://api.oletoken.ai/v1/chat/completions' \
-H "Authorization: Bearer $OLETOKEN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4",
"messages": []
}'
