Messages API 现在可以在 Claude API 上按需压缩对话,该功能处于测试阶段,使用 compact-2026-09-04 测试版标头。发送顶层 compaction 参数,API 会返回一个经过签名的压缩块,用于总结你发送的消息。在后续请求中,将该块放在最前面,以替代那些消息。你可以选择何时压缩,请求可以在后台运行,并且你可以在摘要之后逐字保留最近的对话轮次。在支持保留思考的模型上,这些保留轮次中的思考可以保持有效。
The Messages API can now compact a conversation on demand on the Claude API, in beta with the compact-2026-09-04 beta header. Send the top-level compaction parameter, and the API returns a signed compaction block that summarizes the messages you sent. On later requests, send that block first, in place of those messages. You choose when to compact, the request can run in the background, and you can keep recent turns word for word after the summary. On models with preserved thinking, the thinking in those kept turns can stay valid.
本文内容采集自官方网站,排版和翻译可能与原页面存在差异。
阅读官方全文