Skip to content
中文

Compact Session (Extension)

Call Create session first and replace the example session ID with its returned ID.

POST/agent/v1/sessions/{session_id}/compact● Supported

Request parameters

  • session_idstringrequired

    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.

  • instructionsstringoptional

    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/cancelled 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

Request

curl
# Call Create session first and replace the example session ID with its returned ID.
curl https://api.deepraxis.com/agent/v1/sessions/sesn_123/compact \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
Python
# Call Create session first and replace the example session ID with its returned ID.
import requests

opts = dict(
    base_url="https://api.deepraxis.com/agent",
    api_key="$PRAXIS_API_KEY",
)

# /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
resp = requests.post(
    f"{opts['base_url']}/v1/sessions/sesn_123/compact",
    headers={"Authorization": f"Bearer {opts['api_key']}"},
    json={},
)
print(resp.status_code, resp.json())
TypeScript
// Call Create session first and replace the example session ID with its returned ID.
const opts = {
  baseURL: "https://api.deepraxis.com/agent",
  apiKey: "$PRAXIS_API_KEY",
};

// /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
const resp = await fetch(`${opts.baseURL}/v1/sessions/sesn_123/compact`, {
  method: "POST",
  headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({}),
});
console.log(resp.status, await resp.json());

Response 200

{
  "type": "session_compaction",
  "id": "compact_584a8f3a-f204-4997-9261-ac9b725cf141",
  "status": "skipped",
  "reason": "No complete older turn can be compacted safely"
}

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, failed and cancelled are final.
reason string Why the compaction was skipped, failed or cancelled; 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, failed and cancelled are final.
reason string Why the compaction was skipped, failed or cancelled; absent otherwise.