Archive a session
POST /v1/sessions/{session_id}/archive
Ends a session permanently. Its history stays readable.
The status becomes terminated. After that, sending an event to the session returns 400, and an open stream
ends with an invalid_request_error frame. Archiving an archived session returns it unchanged. To remove a
session’s data permanently, delete it instead. To list archived sessions, call
List sessions with include_archived=true.
You can archive a running session. Its current turn is not cut short, and the run stops once the turn is over.
To stop the turn at once, send a user.interrupt before you archive.
The key must have the tasks:create capability. For what each capability allows, see Keys.
Path parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
session_id | string | Yes | The ID of the session to archive. |
Response
Returns 200 with the session object. For every field, see Sessions.
{ "id": "dd13d728-93e3-440a-874c-4efeb58c97e0", "agent": { "id": "6f1c2a9e-0d4b-4c57-9a3e-2b7d8e1f4c60", "description": "Answers questions about the sales pipeline", "execution_identity": { "type": "service_account" }, "mcp_servers": [], "model": { "id": "default" }, "multiagent": null, "name": "Research Assistant", "skills": [], "system": null, "tools": [], "type": "agent", "version": 1 }, "archived_at": "2026-10-21T01:47:50.964Z", "budget": null, "created_at": "2026-10-21T01:42:16.079Z", "environment_id": "env_default", "metadata": {}, "outcome_evaluations": [], "resources": [ { "id": "329409ba-f288-4b44-9c73-14a18150edee", "created_at": "2026-10-21T01:41:11.028Z", "file_id": "329409ba-f288-4b44-9c73-14a18150edee", "mount_path": "inputs/cities.csv", "type": "file", "updated_at": "2026-10-21T01:41:11.028Z" } ], "stats": {}, "status": "terminated", "title": "Quarterly city report", "type": "session", "updated_at": "2026-10-21T01:47:50.964Z", "usage": { "input_tokens": 12, "output_tokens": 318, "cache_read_input_tokens": 133496, "cache_creation": { "ephemeral_5m_input_tokens": 2210, "ephemeral_1h_input_tokens": 0 }, "active_seconds": 7.331, "list_cost": { "amount": "6", "currency": "USD" } }, "vault_ids": []}Errors
This endpoint can return these errors as well as the common errors.
| Status | error.type | Cause and fix |
|---|---|---|
| 403 | permission_error | The key does not act for the session’s owner, or the owner is no longer an active member. Use the owner’s personal key or the service account key that created the session. |
| 404 | not_found_error | No session with this ID exists, or this key can’t read it. Check the session ID. |
Example
curl -sS -X POST "$CONTEXT_BASE_URL/v1/sessions/dd13d728-93e3-440a-874c-4efeb58c97e0/archive" -H "x-api-key: $CONTEXT_API_KEY"session = client.beta.sessions.archive("dd13d728-93e3-440a-874c-4efeb58c97e0") # status becomes "terminated"const session = await client.beta.sessions.archive("dd13d728-93e3-440a-874c-4efeb58c97e0") // status becomes "terminated"