压缩会话(扩展)
请求压缩会话上下文并获取操作回执。
先调用「创建会话」,用返回的会话 ID 替换示例 ID。
/agent/v1/sessions/{session_id}/compact● 支持请求参数
session_idstring必填path: Session id (sesn_...), as returned by sessions.create or sessions.list. The same id is also accepted as the session_id query parameter on resource and thread calls, where it must equal the path value.
instructionsstring可选Optional focus instructions for the summary, passed to the summarizing model unchanged.
返回
200
仅在 /agent/v1 提供。请求体可省略或为 {},可选 instructions 必须为字符串且原样传递。Idempotency-Key 请求头原样传递;缺失时生成 UUID。响应为 { type: session_compaction, id, status, reason? },id 是操作 ID。queued/running 返回 202;skipped/succeeded/failed 返回 200。非字符串 instructions 返回 400 invalid_request_error。不存在或不可见的托管会话返回 404 not_found_error。
错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码
响应
HTTP 200
Skipped, succeeded or failed compaction
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| type | string | Always `session_compaction`. Result of a compaction request. |
| id | string | Compaction operation id; pass it as operation_id to sessions.compact.retrieve. |
| status | string | State of the compaction operation: queued and running are in progress, skipped means nothing needed compaction, succeeded and failed are final. |
| reason | string | Why the compaction was skipped or failed; absent otherwise. |
HTTP 202
Queued or running compaction
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| type | string | Always `session_compaction`. Result of a compaction request. |
| id | string | Compaction operation id; pass it as operation_id to sessions.compact.retrieve. |
| status | string | State of the compaction operation: queued and running are in progress, skipped means nothing needed compaction, succeeded and failed are final. |
| reason | string | Why the compaction was skipped or failed; absent otherwise. |