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. The simplest create is empty and starts idle, then you send it work. To start a session running in a single call, pass an initial message — it is enqueued as the first input and the agent begins its first turn immediately.
You can still create a session without input and drive it in two steps — useful when you want to attach resources or start streaming before the first turn:
Both forms accept the same creation options — completion window (immediate / priority / loose), a session budget, agent overrides, 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.
TypeScript
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 session.stream({ fromSeq }) 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 — or removing it entirely — auto-resumes the paused session from exactly where it stopped, with no need to re-send the last message. 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. A session.usage event is emitted before every idle or terminal transition, 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. Accepts a name or an agt_ id.
string
Initial input. When present, the session starts running instead of idle.
string
default:"agent default"
Override the completion window: immediate, priority, or loose.
number
A session-local spend cap. On the wire this is sent as integer micro-USD (budget_micro_usd); the CLI --budget-usd and SDK helpers convert dollars client-side. Reaching it pauses the session with stop_reason: "budget_paused".
object
A JSON Schema for a structured result. Overrides the agent’s default. When set, the idle session carries a typed structured_output.
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) An existing computer (cmp_...) to attach instead of a fresh sandbox.
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
(Phase 4) An outcome (out_...) to grade the run against a rubric.
object
Arbitrary key-value pairs stored on the session and echoed on its events.

Next: session operations

Retrieve, list, interrupt, archive, and delete sessions.