Skip to Content
模型用法GPT概覽

GPT 系列

OpenAI 的 GPT 文字模型,包括 GPT-6、GPT-5.x、GPT-4.1、GPT-4o 與 Codex 系列。透過 OpenAI 相容介面呼叫,支援 Chat Completions 與 Responses 兩種介面,官方 OpenAI SDK 只需修改 base_url 即可使用。

常見任務

模型

所有模型皆支援工具呼叫與結構化輸出;除 GPT-5 nano 外皆支援圖片輸入。完整的模型清單與即時價格請參閱模型頁 ,也可透過 Models API 查詢。

常用模型 ID(呼叫時原樣複製)
GPT-6 Solopenai/gpt-6-sol
GPT-5.4openai/gpt-5.4
GPT-5.4 miniopenai/gpt-5.4-mini
GPT-4.1 miniopenai/gpt-4.1-mini不推理,適合簡單任務

模型 ID 可省略 openai/ 前綴,例如 gpt-5.4。回應中的 model 欄位一律為帶前綴的寫法。

介面選擇

重點Codex 系列與 GPT-5.4 Pro 僅支援 Responses 介面;其餘模型兩種介面皆可使用。
Chat CompletionsResponses
位址POST https://api.ofox.ai/v1/chat/completionsPOST https://api.ofox.ai/v1/responses
輸入messagesinput(字串或訊息陣列)
輸出長度上限max_completion_tokens(也接受 max_tokens)max_output_tokens
推理強度reasoning_effortreasoning.effort
推理摘要不回傳reasoning.summary,請見推理摘要
網路搜尋不支援web_search 工具
僅支援此介面的模型—openai/gpt-5.4-pro、openai/gpt-5.3-codex、openai/gpt-5.2-codex

完整的請求參數請見 Chat Completions API 與 Responses API。

供應商

供應商提供的模型
Azure AI Foundry(azure_foundry)所有模型,預設供應商
OpenAI(openai)GPT-6 Sol、GPT-6 Luna、GPT-6 Astra、GPT-5.6 Sol、GPT-5.6 Terra、GPT-5.6 Luna

實測兩家供應商在推理、快取與網路搜尋上的表現一致。需要指定供應商時,在請求標頭中加入 X-OfoxAI-Provider-Type: openai,其他方式請見供應商路由。

呼叫範例

gpt_chat.py
import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.ai/v1", api_key=os.environ["OFOX_API_KEY"]) resp = client.chat.completions.create( model="openai/gpt-5.4", messages=[ {"role": "system", "content": "你是一名資深後端工程師,回答簡潔。"}, {"role": "user", "content": "用一句話解釋什麼是冪等性。"}, ], ) print(resp.choices[0].message.content)

提示快取

重點GPT 系列會自動快取,不需要修改請求;將固定內容放在請求開頭即可提高命中率。

請求的前綴與近期請求一致且夠長時,會自動命中快取,命中部分依快取讀取單價計費。

項目說明
確認命中Chat Completions 中 usage.prompt_tokens_details.cached_tokens 大於 0;Responses 中為 usage.input_tokens_details.cached_tokens
寫入GPT-6、GPT-5.6 系列首次請求時會回傳 prompt_tokens_details.cache_write_tokens,依快取寫入單價計費
最小長度前綴過短時不會快取,最小長度請見 OpenAI 官方文件 
穩定性快取採盡力而為,前綴相同的請求也可能未命中

快取的通用說明請見提示快取。

在 Responses 介面的 tools 中加入 web_search,模型會自行發起搜尋並引用來源。Chat Completions 不支援網路搜尋。

gpt_web_search.py
import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.ai/v1", api_key=os.environ["OFOX_API_KEY"]) resp = client.responses.create( model="openai/gpt-5.4", tools=[{"type": "web_search"}], input="Python 最新的穩定版本是多少?", ) print(resp.output_text) print("搜尋次數:", sum(1 for item in resp.output if item.type == "web_search_call"))

output 中的每個 web_search_call 項目代表一次搜尋,message 項目為最終回答。搜尋按次計費,單價請見模型頁 。

常見錯誤

重點參數錯誤會回傳 400 並說明原因;長時間推理偶爾會出現 502、504,建議使用串流輸出並設定較長的逾時。
HTTP · type錯誤原文原因處理方式
400 invalid_request_errorThis model's maximum context length is 128000 tokens. However, your messages resulted in 152008 tokens.輸入超過模型上下文縮短輸入,或改用上下文更長的模型
400 invalid_request_errormax_tokens is too large: 100000. This model supports at most 16384 completion tokens輸出上限超過模型允許的最大值調低 max_completion_tokens
400 invalid_request_errorInvalid value: 'bogus'. Supported values are: 'low', 'medium', 'high', and 'xhigh'.該模型不支援此 reasoning_effort 取值改用錯誤訊息中列出的取值
400 endpoint_not_supportedModel 'openai/gpt-5.4-pro' does not support the /v1/chat/completions endpoint on this platform.該模型僅支援 Responses 介面改用 /v1/responses
404 model_not_foundModel 'openai/gpt-9' not found模型 ID 拼錯或模型已下架從本頁複製模型 ID
429 rate_limit_errorRate limit reached for the requested model. Please retry after a short delay.請求過於頻繁稍後重試,請見速率限制
502 upstream_errorThe model service is temporarily unavailable. Please retry or switch to another model.上游服務暫時無法使用稍後重試,或改用其他模型
504 gateway_timeoutThe upstream service did not respond in time.推理時間過長,上游未在時限內回應使用串流輸出,或降低推理強度
200,finish_reason: "length" 且回答為空—推理用盡了 max_completion_tokens調高 max_completion_tokens,或降低推理強度

其他通用錯誤請見錯誤處理。

官方文件

官方文件描述的是直連 OpenAI 時的行為。在 OfoxAI 上呼叫時,模型 ID 與介面位址以本頁為準。

常見問題

GPT 的模型 ID 怎麼寫?

標準寫法為 openai/gpt-5.4,也可以省略 openai/ 前綴,寫成 gpt-5.4。

Chat Completions 和 Responses 該用哪個?

兩者皆可。Codex 系列與 GPT-5.4 Pro 僅支援 Responses;需要推理摘要或網路搜尋時也必須使用 Responses。已有 Chat Completions 程式碼的專案可繼續使用。

GPT 如何開啟推理?

Chat Completions 傳入 reasoning_effort(如 "high"),Responses 傳入 reasoning: {"effort": "high"}。部分模型預設不推理,需要時請明確傳入。

GPT 回傳的內容為空,finish_reason 是 length?

推理消耗的 token 會計入 max_completion_tokens,推理用盡額度後就不會再輸出回答。請調高 max_completion_tokens,或降低 reasoning_effort。

出現 does not support the /v1/chat/completions endpoint 錯誤?

該模型僅支援 Responses 介面,例如 gpt-5.4-pro、gpt-5.3-codex、gpt-5.2-codex。請改用 POST /v1/responses。

GPT 可以看到推理過程嗎?

使用 Responses 介面並傳入 reasoning: {"effort": "medium", "summary": "auto"},output 中的 reasoning 項目會包含推理摘要。Chat Completions 不回傳推理內容。

GPT 可以網路搜尋嗎?

可以,使用 Responses 介面並在 tools 中加入 {"type": "web_search"}。Chat Completions 不支援網路搜尋。

GPT 的提示快取需要手動開啟嗎?

不需要,前綴夠長且與近期請求一致時會自動命中,命中量請見 usage 中的 cached_tokens。

GPT 請求逾時或回傳 504 該怎麼辦?

高強度推理可能耗時較長。建議使用串流輸出(stream: true),將用戶端逾時設定為 600 秒以上,或降低 reasoning_effort。

最後更新於