Overview

The /beta/sessions API is the durable, server-side contract for managed agent runs. A session represents a long-lived conversation thread or task run between a user and an agent. It tracks message history as immutable events, enforces execution budgets (tokens, turns, tool calls), supports child threads via parent_thread_id, and can carry session-scoped files and credentials. Sessions are scoped to the authenticated user. Accessing another user’s session returns 404 Not Found so existence is never leaked.

Base URL

All beta session endpoints are mounted under:
Authentication is required via a Bearer token in the Authorization header. See Authentication for details.

The session object

Budget and truncation strategies

Budgets are optional limits enforced when events are appended. When context_window is set and projected usage crosses 80%, a context_warning event is emitted. When a hard max_* limit is exceeded, the append is rejected and a budget_exceeded event is recorded.

Endpoints

List sessions

Query parameters

Response

Create a session

Request body

Response

Get a session

Response

Update a session

Request body

At least one field must be provided.

Response

Archive a session

Archiving sets status to archived, sets archived_at, and prevents new events from being appended or the session from being interrupted.

Response

Archiving is currently a soft-delete. Archived sessions cannot receive new events or interrupts.

Append an event

Events are the immutable audit trail of a session. Only a subset of event types may be appended by callers.

Request body

Response

If the event would exceed a budget limit, accepted is false and the returned event has type budget_exceeded:

List events

Response

The list is ordered by descending sequence and limited to the most recent 200 events.

Stream events (SSE)

Open a long-lived Server-Sent Events stream. Each event corresponds to one row in beta_session_events.
Optional query parameter after=<sequence> resumes the stream after a known sequence number.

Stream format

The server emits a keep-alive comment every 15 seconds.

Stream events (WebSocket)

The WebSocket endpoint delivers the same events as SSE and is useful when you need bidirectional control, such as sending an interrupt.
Each message is a JSON object:
Use the after query parameter to resume from a known sequence.

Search session memory

Performs a simple substring search across the most recent 200 events.

Response

Interrupt a session

Emit a user_interrupt event into an active session. The payload must be an object.

Response

Edit context

Delete or summarize ranges of events to manage the context window. This mutates event history and reduces tokens_used.

Operation object

Response

Session resources

Resources attach credentials or references to a session. Values are encrypted at rest; references point to an external vault or secret store.

Supported resource kinds

Attach a resource

Either value or ref must be provided, but not both.

Response

List resources

Delete a resource

Returns 204 No Content on success.

Session files

Upload and retrieve binary files scoped to a session. Files are stored on the server’s local data_dir/session-files and returned as base64.

Upload a file

Response

List files

Get a file

The response includes the base64 content:

Delete a file

Returns 204 No Content.

Tool context budget

Control how tool results occupy the active context window.

Get tool context

Response

Set tool context

Tool-context config fields

Error codes