跳至主要內容

/responses/compact

使用 OpenAI 的 /responses/compact 端點壓縮對話歷史。

功能支援
支援的 LiteLLM 版本1.72.0+
支援的提供者openai

用法

LiteLLM Python SDK

Compact Response
import litellm

response = litellm.compact_responses(
model="openai/gpt-4o",
input=[{"role": "user", "content": "Hello, how are you?"}],
instructions="Be helpful",
previous_response_id="resp_abc123" # optional
)

print(response.id)
print(response.object) # "response.compaction"
print(response.output)

LiteLLM Proxy

Compact Request
curl http://localhost:4000/v1/responses/compact \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-1234" \
-d '{
"model": "openai/gpt-4o",
"input": [{"role": "user", "content": "Hello"}],
"instructions": "Be helpful"
}'

請求參數

參數類型必填描述
modelstring用於壓縮的模型
inputstring or array要壓縮的輸入訊息
instructionsstring系統指示
previous_response_idstring要接續的前一個回應 ID

回應格式

{
"id": "resp_abc123",
"object": "response.compaction",
"created_at": 1734366691,
"output": [
{
"type": "message",
"role": "assistant",
"content": [...]
},
{
"type": "compaction",
"encrypted_content": "..."
}
],
"usage": {
"input_tokens": 100,
"output_tokens": 50,
"total_tokens": 150
}
}
🚅
LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →