Skip to main content
POST
Create a session
Creates a session that runs an agent on a task. With a free slot, the session starts pending and moves to running once the agent launches. Above your concurrency limit it is accepted as queued and starts when a slot frees up (set queue: false to get a 429 instead). Returns 201 with the created session object, status pending or queued.

Headers

string
Optional idempotency key (1 to 255 characters). Safe retry within 24 hours: the same key returns the original session. Reusing it with a different body returns 422.

Request body

string | object
required
A catalog identifier (e.g. "h/web-surfer-flash") or an inline agent, which follows the same rules: environments is required (at most one per kind) and may be [] only with subagents or custom tools. The session reads environments, skills, and subagents from the agent.
string | object | object[]
The initial task, queued before the agent’s first step: a plain string (one user message), one message object, or a list. Each message object has:
  • type (string, optional): "user_message", the default.
  • message (string, required): the instruction or task.
  • images (string[], optional): base64 data URIs to attach (e.g. data:image/png;base64,...).
  • files (object[], optional): files to attach, up to 10 and 7 MB in total. Each is { name, source, type: "base64", media_type? } (media_type is guessed if omitted). Saved under files/ in a workstation or code sandbox workspace, and ~/Downloads on a cloud browser.
  • caller_id (string, optional): the sender. Defaults to user. Leave it unset for normal user input.
integer
Cap on steps, where each step is one decide-and-act cycle. Minimum 1. At the cap the agent is asked for a final answer from what it has so far (it is not hard-killed). Omit to run uncapped.
number
Cap on wall-clock seconds, greater than 0. At the cap, as with max_steps, the agent is asked for a final answer. Omit to run uncapped.
integer
Switches between one-shot and interactive. Leave it null for a one-shot task: the session ends when the agent answers. Set it (seconds, greater than 0) to keep the session open for follow-up messages: after each answer the session goes idle and waits this long for your next message.
integer | null
Minutes after the session finishes before it is deleted, with its events and screenshots. Minimum 1. Omit it to keep the session for the retention period in your privacy settings. A value deletes it sooner. null adds no expiry beyond that period.
integer | null
Minutes after the session finishes before its screenshots are deleted, to expire visual data sooner than the session. Minimum 1. Omit it or pass null to keep screenshots as long as the session.
boolean
default:"true"
At your concurrency limit, accept the session as queued instead of rejecting it with 429. Queued sessions don’t count against your quota and start oldest first as running sessions finish. Set false to fail fast.
string
Tag for grouping related sessions. Filter on it with GET /sessions?group_id=....
string
Parent session id, for multi-agent runs. The parent’s status lists this session in subagent_session_ids. Child sessions never queue: at capacity the create fails with 429 even when queue is true, since a child queued behind its own parent would deadlock it.
object
Per-run tweaks applied after the agent (and its environments, skills, and subagents) are resolved, so you can adjust a catalog agent for one run. Keys are dotted paths, and [field=value] selects list members. Each value is validated against the field it targets: an unknown path or wrong type returns 422. See Overrides.

Examples

Basic session

Reference a catalog agent. Its stored spec supplies the environments:
Response

With idempotency key

With an inline agent

Pass an inline agent instead of a catalog id to set environments (or any other field) per session. Environments nest under agent.

With per-run overrides

Send a catalog agent to a different start URL for this run only:

Child session (multi-agent)

See Multi-agent.

Errors