API 參考

Responses

POST/v1/responses

OpenAI Responses API 格式——單個 input 欄位、結構化 output 項目,支援推理摘要的模型會一併回傳。

#請求參數

  • modelstring必填

    來自 /v1/models 的模型 ID。閘道據此解析上游廠商。

  • inputstring | array必填

    提示詞:純字串或 input 項目陣列。

  • instructionsstring選填

    系統層級指令,等同於 system 訊息。

  • streamboolean選填

    以串流回傳 response.* SSE 事件,而不是單個 JSON。

  • max_output_tokensinteger選填

    生成 token 上限;同時限定預留額度的估算。

  • toolsarray選填

    模型可呼叫的函式宣告——見工具呼叫指南。

  • previous_response_idstring選填

    在上一個回應上續接一輪,無需重發歷史。

#壓縮長對話

POST/v1/responses/compact

當一段對話長到不適合每輪都重送時,compaction 會把它壓縮,並回傳可以繼續往下帶的精簡版本。程式設計類 Agent 在工作階段接近上下文上限時呼叫的就是它。

  • modelstring必填

    支援 compaction 的模型。其他模型會以 unsupported_endpoint 拒絕這個路徑。

  • inputarray | string選填

    待壓縮的對話,使用 Responses 的 input 格式。

  • instructionsstring | array選填

    壓縮時需要保留什麼——例如「保留所有檔案路徑和已做的決定」。

  • previous_response_idstring選填

    從已儲存的回應繼續,無需重發整段歷史。

compacted.json
{
  "id": "resp_…",
  "object": "response",
  "created_at": 1789000000,
  "output": [ /* the compacted conversation */ ],
  "usage": {"input_tokens": 8120, "output_tokens": 240, "total_tokens": 8360}
}

不支援串流,按 token 計費

compaction 沒有串流形式——這個請求不接受 stream:true。它和一般 Responses 呼叫一樣,按讀入和寫出的 token 計費,所以要在需要時才壓縮,而不是每輪都壓。

#相關錯誤碼

  • 400 invalid_request_error請求主體格式錯誤,或該模型不支援某個參數。
  • 401Bearer 權杖無效或缺失。這條路徑不帶 error.code,請依狀態碼判斷。
  • 402 insufficient_user_quota錢包餘額不足以覆蓋預扣估算。
  • 429金鑰級限流。回應主體為空,按 Retry-After 等待。若 429 帶有 insufficient_user_quota,那是每日消費上限,不是限流。
  • 503 model_not_found模型名稱不存在,或目前沒有健康的通道可以提供服務。

完整錯誤碼表 →

#請求範例

curl https://www.aisplice.store/v1/responses \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "input": "Say hello."
  }'

#回應

response.json
{
  "id": "resp_…",
  "object": "response",
  "model": "gpt-5.6-luna",
  "output": [{
    "type": "message",
    "role": "assistant",
    "content": [{"type": "output_text", "text": "Hello!"}]
  }],
  "usage": {"input_tokens": 9, "output_tokens": 3, "total_tokens": 12}
}

還是沒解決?

把請求 ID 或錯誤訊息傳給我們,我們來查。