Skip to main content
A session is a conversation you can keep appending events to. Compared with passing session_id to POST /v1/agents/run yourself, the sessions API lets you create, inspect, replay, and interrupt it explicitly.
Creating a session provisions no sandbox and costs nothing. The sandbox is provisioned on the first event, and billing follows events — not the existence of a session.

Create a session

string
required
Agent (Expert) identifier.
string
Session title. Defaults to “New Chat”.
string
Environment id. Resolved at every run, so editing the environment takes effect on the next event.
curl

Send an event (SSE)

string
default:"user.message"
Only user.message is supported today; anything else returns 400.
string
required
Message content.
string
required
Text model id for this turn. Missing or blank returns Missing required field: model. Token billing uses this name, not the Expert’s selected model. Image and video billing ignore this field.
string[]
Up to 20 file ids returned by Files.
The response is an SSE stream with exactly the same event vocabulary as Invoke an Expert — both endpoints run through one shared execution path.
curl
Once the handshake succeeds, the X-Session-Id response header is the coordinate of this turn. Closing the SSE connection does not stop generation.

After the connection drops

A run is addressed by session id. SSE is a subscription. The id comes from the X-Session-Id header on POST /v1/agents/run or on this endpoint, before the body finishes. Closing the connection does not cancel the turn. The model keeps generating, and tool calls and billing continue. To stop, call interrupt below. To keep reading tokens as they are produced:
curl
While the turn is still generating, the response is text/event-stream with the same events as sending an event. When the turn has finished, the response is 204 with an empty body. Read the persisted log instead. Posting the same body to POST /v1/agents/run, or posting the same content to this session’s POST .../events, resubscribes. It does not start another turn and does not insert another user message. A different body while the turn is still running returns 409:
Call interrupt, then send the new body. A request that carries tool_confirmations resumes the same turn and is not rejected as a different body. /v1/chat/completions is outside this contract. It is synchronous: disconnecting cancels that request.

Replay history

By default this returns the persisted user and assistant messages as JSON, not SSE. Messages are written incrementally while the turn runs, so after it finishes this is the full log. To follow tokens that are still being produced, use ?live=1 from the previous section.
curl
Response:
An unknown after cursor replays from the beginning rather than returning an empty page — empty would be indistinguishable from “caught up”. limit maxes out at 200.

Interrupt a run

Asks the runtime to stop generating. Closing the SSE connection does not stop the turn. This is idempotent: interrupting a session with nothing running still succeeds, because the intent (“stop”) is already satisfied.
curl

Other operations

Errors

Next steps

Environments

Define sandbox runtime and dependencies

Manage Agents

Create and publish Experts via API