技術指南

OpenAI 回應 API 與聊天完成

OpenAI 建議在新專案中使用 Responses API,同時持續支援 Chat Completions。

聆聽此指南AI 語音敘述 · ~3 min

本頁閱讀時間3分鐘
  1. 概述
  2. 深入探討
  3. 現實世界的實施
  4. OpenAI Responses API 與 Chat Completions 的未來走向
  5. 付諸實踐
  6. 不斷探索
  7. 常見問題

概述

它們的 request、response、tool 與 conversation‑state 介面不同,開發者應依模型支援與產品需求選擇,並以 2026 年 9 月 26 日的官方文件為準。

深入探討

OpenAI’s Responses API is its recommended interface for new projects as of September 26, 2026; Chat Completions remains supported. Responses accepts input and returns a typed output list that can contain messages and tool-related items. Chat Completions accepts a role-tagged messages array and returns choices containing messages. Both APIs support text generation, and OpenAI documents function calling and structured outputs for each, but request and response schemas differ. Responses offers platform tools such as web search and file search, and its multi-turn options include previous_response_id and the Conversations API. Chat Completions does not automatically provide the same conversation history; the application generally resends the messages it wants the model to consider. State and storage are configurable, so stateful does not mean the service automatically remembers every user across calls. Check current data controls and model compatibility before relying on a feature. For a simple existing integration, Chat Completions may remain a reasonable fit when its capabilities meet the need. A new agentic workflow that needs built-in platform tools may benefit from Responses. Migration involves more than changing an endpoint: update input fields, parse output items, adapt function/tool flow, and test streaming, structured outputs, errors, and storage settings. OpenAI’s documentation should be treated as the authority for the current feature matrix. Endpoint and tool availability can vary by model, so confirm support for the exact model and project before relying on a capability.

現實世界的實施

使用 Chat Completions 的應用程式會在每次請求時重新傳送整個對話陣列,而同樣的應用程式若改用 Responses API,則只需傳遞 previous_response_id 以延續對話,無需重新傳送歷史記錄。

開發者若想內建網路搜尋,可在 Responses API 呼叫中將其作為工具加入,而不必自行撰寫呼叫搜尋 API 的程式碼並手動將結果插入訊息陣列。

一個團隊在遷移支援機器人時,將手動管理訊息陣列的迴圈改為儲存 OpenAI 回傳的 response ID,並在下一回合傳回該 ID。

一個已經擁有健全自訂訊息歷史邏輯的舊版整合,仍然使用 Chat Completions,而不是將其狀態管理重新設計為新的 API 結構。

OpenAI Responses API 與 Chat Completions 的未來走向

OpenAI 目前的文件建議在新專案中使用 Responses,並表示仍支援 Chat Completions。新工具與模型功能可能會改變比較結果,而舊有整合可能會優先考慮相容性與較簡單的訊息格式。在做實作選擇前,請重新檢查遷移指南、模型特定支援、資料控制與 SDK 行為;不要假設每個功能或參數都是可互換的。請為您的產品實際使用的請求與回應路徑維持一套小型回歸測試,並清楚標註任何相容性聲明的日期。

付諸實踐

為什麼這很重要

  • 成本與預算. 多年來,架構決策決定著效能和營運成本。
  • 更明確的決策. 技術教育幫助團隊選擇正確的堆疊,而不僅僅是最新的堆疊。
  • 品質管控. 更好的工程選擇可以減少生產中的可靠性事故。

留意

  • 優化一項基準測試可以隱藏更廣泛的系統弱點。
  • 基礎設施和維護成本常常被低估。
  • 隨著系統變得更加複雜,安全性和可觀察性差距可能會擴大。

後續步驟

  1. 在實施之前定義延遲、品質和成本目標。
  2. 在實際負載和資料條件下進行基準測試。
  3. 儀器監控錯誤、漂移和使用者影響。
  4. 在擴展之前準備回滾和事件回應路徑。

不斷探索

免費電子報

獲取每日 AI 簡報

每個工作日上午提供三則經過驗證的 AI 新聞,以淺顯易懂的英文撰寫。永久免費,無廣告。

每個工作日一封電子郵件。一鍵取消訂閱。我們絕不出售或分享您的地址。

測試一下自己

參加 OpenAI Responses API 與 Chat Completions 小測驗

每個答案皆有即時回饋,通過課程後可獲得具備可驗證 ID 的可分享證書。

開始測驗

支持免費的 AI 教育。AI Understanding 是一個 501(c)(3) 非營利組織——絕無廣告,絕無付費牆。 捐款

常見問題

什麼是 OpenAI Responses API 與 Chat Completions?

OpenAI 建議在新專案中使用 Responses API,同時持續支援 Chat Completions。它們的請求、回應、工具與對話狀態介面不同,開發者應依模型支援與產品需求來選擇,並查閱截至 2026 年 9 月 26 日的官方文件。

根據引用的 OpenAI 文件,Responses 如何在回合之間保留對話上下文?

OpenAI 文件明確說明可使用 previous_response_id 以及持久化的 Conversation 物件;狀態不會自動跨越每一個任意的請求。

Responses API 提供了什麼內建功能,之前在 Chat Completions 中需要自行實作?

Responses API 能在伺服器端執行如網路搜尋或檔案搜尋等工具,這在以前需要開發者呼叫外部 API 並手動插入結果。

Responses API 的輸出結構與 Chat Completions 有何不同?

Responses API 的回應物件可以包含多個輸出項目,與 Chat Completions 單一 choices[0].message 形式不同。

OpenAI 目前對 Chat Completions 的說法是什麼?

OpenAI 的目前遷移指南建議使用 Responses 針對新專案,並指出 Chat Completions 仍受支援。

開發者在假設某個 API 功能能與特定模型配合使用前,應該先檢查什麼?

端點可用性與功能支援可能因模型而異;目前文件為相容性的來源。