Skip to main content
A session is one run of an agent. You control it directly: send input, stream events, interrupt it, adjust its budget, and read the files it produced. State is durable — a session can run for hours, survive restarts, and sit idle for days at storage cost only.

Lifecycle

Sessions progress through these statuses:
There is no mandatory “deliver” step. When a turn yields control the session goes idle with a stop_reason and stays resumable — you can send more input for days. It reaches completed only when the agent declares the task done. Anything worth keeping is written to Files via publish_file; scratch work stays in the session’s sandbox.

Create a session

A session inherits its agent’s configuration. Every create takes an initial message (an empty one is rejected with 400) — it is enqueued as the first input and the agent begins its first turn immediately.
Follow-up work goes through sessions.send once the turn is idle:
Both forms accept the same creation options — completion window (immediate / priority / loose), a session budget, and the attachable resources below.

Attach resources at create

Beyond the agent’s own configuration, a create call can bind extra resources to the session:
TypeScript

Override agent configuration for a session

(Coming soon.) Session-local overrides for the agent’s model, system, skills, tools, or computer are not yet accepted on create — today you pin behavior with agent_version or create a new agent version. When overrides land they will be session-local and never propagate back to the agent or its versions. Override semantics:
  • Arrays replace in full — they are not merged. Passing skills or tools in overrides swaps the agent’s list wholesale rather than unioning with it.
  • model cannot be cleared. You may point a session at a different model, but every session has one; passing an empty value is rejected.
  • Nothing flows back. When the session ends, the agent definition is exactly as it was before.

Send work and stream

TypeScript
The stream is resumable by sequence: reconnect with naive.stream(session.id, { afterSeq }) to replay everything after a seq you already handled — no gaps, no duplicates. See Events & streaming.

Session budgets

A session can carry its own cap, independent of the agent’s period budget. When the running total reaches the cap, the session pauses: it goes idle with stop_reason: "budget_paused" and stops pricing new calls. Raising the cap auto-resumes the paused session from exactly where it stopped, with no need to re-send the last message. A cap cannot be removed (null is validation_failed). See Budgets.
CLI

Stop reasons

Every time a session goes idle, the session.idle event and the session record carry a stop_reason — a string describing why the turn ended:

Retrieving results after idle

When a session goes idle, its durable outputs are the files it published, its event history, and — when an output schema is set — a typed structured_output. Scratch work stays in the session’s sandbox and is not returned — the agent promotes anything worth keeping with publish_file.

Structured results

By default an agent’s durable output is the files it published plus its event history. When you also want a machine-readable result, set an output_schema (a JSON Schema) — on the agent as a default, or per session as an override. When the session goes idle having satisfied the schema, the session object carries a typed structured_output object alongside its files and events, so a caller can read the result directly instead of parsing the transcript.
TypeScript
The same typed structured_output is included on the session.idle deployment payload, so an unattended fire returns a structured result without a transcript replay.

Cost and usage

Every session object carries its running cost and token usage, so you never have to reconstruct spend from the transcript. consumed_micro_usd is the cumulative cost in integer micro-USD, and token_usage breaks the model tokens into the five metered tiers — input, cache_write, cache_read, output, and reasoning. consumed_micro_usd counts everything billed to the session — model calls and priced tool calls — but not the agent’s computer time, which is billed to the agent and shows as its computer component. A session.usage event is emitted before every idle or terminal transition, carrying the same running total as the session object, and the fuller export path is described in Observability.

Update the agent mid-session

(Coming soon.) Session-local updates to tools and mcp_servers while a session is idle are not yet served — today, changing tools means a new agent version (or a new session). When this lands, updates will be a full replacement of the provided array and session-local.

Create parameters

string
required
The agent to run, by its agt_ id. An unknown id is not_found (404).
string
required
Initial input; the session starts running. An empty or whitespace-only message is refused with validation_failed.
string
default:"agent default"
Override the completion window: immediate, priority, or loose.
integer
default:"current version"
Pin an exact version of the agent.
integer
A session-local spend cap in integer micro-USD (the CLI --budget-usd converts dollars client-side). Reaching it pauses the session with stop_reason: "budget_paused".
string
The persona this task acts as — an idn_ id or the persona’s name. Answered as identity_id on the session.
string
default:"build"
plan starts the session in plan mode; build is the default.
object
A JSON Schema for a structured result. Overrides the agent’s default. When set, the idle session carries a typed structured_output.
boolean
When true, a session that cannot produce a conforming object goes idle with stop_reason: "error". Requires an output_schema on the session or the agent.
object
(coming soon) Session-local replacements for the agent’s model, system, skills, tools, or computer. Arrays replace in full; model cannot be cleared.
string
(coming soon) A computer (cmp_...) to work on. Today every session works on its agent’s own computer, taken on the first shell or filesystem call.
string[]
(coming soon) Skills to mount for this run.
string[]
(coming soon) Vaults the session may read secrets from — not yet accepted on create.
string
An outcome (ocm_...) to grade the run against from its first turn.
object
Arbitrary key-value pairs stored on the session and echoed on its events.
string
Set when a deployment fired this run.

Next: session operations

Retrieve, list, interrupt, and cancel sessions.