Compact Session (Extension)
Request session context compaction and retrieve an operation receipt.
Call Create session first and replace the example session ID with its returned ID.
/agent/v1/sessions/{session_id}/compact● SupportedRequest parameters
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.
Returns
200
Available only on /agent/v1. The body may be omitted or {}. Optional instructions must be a string and is forwarded unchanged. Idempotency-Key is forwarded unchanged; a UUID is generated when absent. Returns { type: session_compaction, id, status, reason? }, where id is the operation ID. queued/running return 202; skipped/succeeded/failed return 200. Non-string instructions return 400 invalid_request_error. Missing or inaccessible managed sessions return 404 not_found_error.
Errors follow the Anthropic error format (type / message / request_id) — see error codes
Response
HTTP 200
Skipped, succeeded or failed compaction
application/json
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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. |