文本
压缩响应
把长对话压缩成更短的对话,供下一次 Responses 请求使用。
概述
压缩长对话的输入,并返回 response.compaction 对象。它的 output 数组里是下一次创建响应请求要作为 input 发送的项。请原样发送返回的项,并继续使用同一个模型:compaction 项是加密的,其他模型可能不接受。
model必须在accepted_request_formats中包含openai_responses,否则请求返回400。- 此接口不支持
stream,stream: true返回400。 - 按 token 用量计费,与其他 Responses 请求相同。
Codex CLI 使用此接口做远程压缩。
请求
curl -X POST "https://api.tokenlab.sh/v1/responses/compact" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-terra",
"input": [
{"type": "message", "role": "user", "content": "Plan a three-day trip to Kyoto."},
{"type": "message", "role": "assistant", "content": "Day 1: Fushimi Inari and Gion. Day 2: Arashiyama. Day 3: Kinkaku-ji and Nishiki Market."},
{"type": "message", "role": "user", "content": "Add a tea ceremony on day 2."}
]
}'响应
{
"id": "resp_abc123",
"object": "response.compaction",
"created_at": 1706000000,
"output": [
{
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": "Plan a three-day trip to Kyoto."}]
},
{
"id": "cmp_abc123",
"type": "compaction",
"encrypted_content": "gAAAAAB..."
}
],
"usage": {
"input_tokens": 120,
"output_tokens": 30,
"total_tokens": 150
}
}重要字段
objectstring
始终为
response.compaction。outputarray
压缩后的项。请原样作为下一次请求的
input 传入。usageobject
压缩请求的 token 用量。
错误
错误使用 OpenAI 风格的 error 对象:400 表示字段无效或模型不带 Responses 格式,401 表示密钥无效,402 表示余额不足,503 表示模型暂时无法处理该请求。见处理 API 错误。
授权
BearerAuth AuthorizationBearer <token>
API Key 身份验证。在 Dashboard > API > API Keys 中创建或管理 API Key。
位置: header
请求头
X-TokenLab-Delivery-Policy?string
单次请求的交付策略。覆盖 API 密钥和 Workspace 的默认设置。自动优先尝试 TokenLab Verified,并在输出、请求接受或持久资源创建之前,可能会切换一次至仅限 Official。
可选值
- "auto"
- "verified"
- "official"
请求体
application/json
响应
application/json
application/json
application/json
application/json