Skip to main content
A Session is a running workspace for an Agent. It binds an Agent snapshot to an Environment, optional resources, and optional Vault credentials. New Sessions start in idle; send events to start work.

Session Status Lifecycle

A Session is a state machine. The status field on a Session resource takes one of the following values: Two additional lifecycle markers are surfaced outside the status field:
  • Archived: signalled by a non-null archived_at timestamp. The status value itself does not change to archived — the Session remains readable but rejects new events.
  • Cancel response: the POST /api/v1/cloud/sessions/{id}/cancel endpoint always returns a fixed body literal "status": "canceling". This is a response shape, not a Session status — the persisted status reverts to idle once the turn aborts.
1

Created → idle

A new Session starts in idle, awaiting input.
2

idle → running

Sending a user.message event moves the Session into running.
3

running → idle

When the turn completes, the Session returns to idle. Repeat for each turn.
4

running → idle (after cancel)

Cancelling a running Session aborts the turn and the Session returns to idle. The cancel response body uses a fixed "status": "canceling" literal regardless of the persisted status. The Session remains reusable.
5

rescheduling

The runtime may temporarily move into rescheduling while the Session is being rescheduled; it returns to idle once recovery completes.
6

archived / terminated (terminal)

Archival (via archived_at) or termination ends the Session permanently — it cannot be resumed.

Cancel Semantics

  • Cancel on idle: No-op. Returns HTTP 200 and the status stays idle.
  • Cancel on running: Interrupts the Agent. Returns HTTP 202. The Session transitions to canceling, then back to idle once the turn aborts.
  • After cancel: The Session remains reusable — send the next user.message to start a new turn.
Only archived and terminated are terminal states. A cancelled Session always returns to idle and can continue accepting messages.

Sending Messages to a Running Session (409 Error)

If you send a user.message to a Session that is currently running, the API returns HTTP 409:
This is the most common pitfall for new users. Always wait for session.status_idle before sending the next message, or cancel the current turn first.

Create a Session

Create a Session with an existing agent and environment_id:
The create response is a Session object. It includes agent, environment_id, status, resources, vault_ids, deployment_id, outcome_evaluations, stats, environment_variables, archived_at, created_at, and updated_at. Legacy request fields such as environment, delta_flush_interval_ms, memory_store_ids, and vaults are not supported. environment_variables is supported again — see Create a session for the JSON-string request format and validation rules.

Attach Resources at Creation

Attach files, repositories, and Memory Stores in the resources array:
To add a file after creation, use POST /api/v1/cloud/sessions/{session_id}/resources. Current CAS supports post-create add only for file resources. Use the resource list/get/update/delete endpoints to inspect, rotate a GitHub token, or remove resources.

Send Messages

Send user.message events through the Events API. content must be a non-empty array of content blocks:
The send-events endpoint returns HTTP 200 with {"data":[...]}. It accepts these client event types: user.message, user.interrupt, user.tool_confirmation, user.tool_result, user.custom_tool_result, user.define_outcome, and system.message.

Read Events

Use the event stream for live updates:
The stream emits Server-Sent Events with id, event, and data. The stream endpoint supports the Last-Event-ID header for reconnection replay; event type query filters are not currently supported. Use the list endpoint for history and pagination:
List responses use data and next_page.

Read and Update Sessions

Session list uses page / next_page pagination and supports filters such as agent_id, agent_version, deployment_id, memory_store_id, statuses, and created_at[...].

Threads

Managed-agent Sessions can have a coordinator thread and child threads. Thread endpoints use the public session_thread shape and do not include legacy thread fields such as role, name, agent_id, agent_version, or stop_reason.
Child threads can be archived with POST /api/v1/cloud/sessions/{session_id}/threads/{thread_id}/archive. Current CAS returns 409 when asked to archive the coordinator/main thread.

Lifecycle

Archive a Session when it should no longer be used:
Delete a Session when you need removal confirmation:
Delete returns:
The cancel endpoint returns {"id":"...","type":"session","status":"canceling"}. It responds with 202 Accepted when there is an active turn to cancel, and 200 OK (no-op) when the Session is already idle.

Multi-Turn Conversation Workflow

Sessions support multi-turn conversations. The recommended pattern is:
  1. Send a user.message event.
  2. Listen to the SSE stream for updates.
  3. Wait for the session.status_idle event.
  4. Send the next user.message.
Always wait for session.status_idle before sending the next message. Sending a message while the Session is still running returns HTTP 409.

Best practices

  1. Pin Agent versions — In production, always create Sessions with {"id": ..., "type": "agent", "version": ...} so Agent updates do not change Session behavior unexpectedly.
  2. Use metadata — Record business context (task ID, trigger source, etc.) in the metadata field for traceability and debugging.
  3. Cancel promptly — Cancel Sessions you no longer need to free compute resources.

FAQ

Q: What happens if I send a message to a running Session? A: The API returns HTTP 409 with type: "invalid_request_error" and the message “Session is currently processing a turn. Cancel the current turn or wait for completion.” Either cancel the current turn or wait until the Session returns to idle before sending the next message. Q: Can I still use a Session after cancelling? A: Yes. After cancel, the Session transitions from canceling back to idle. You can continue the conversation by sending the next user.message. Only archived and terminated are terminal states. Q: How do I get the full conversation history? A: Use GET /api/v1/cloud/sessions/{id}/events to retrieve all events for the Session, including user messages and Agent responses. Q: How do I reconnect after an SSE disconnect? A: Pass the Last-Event-ID header when reconnecting to the SSE stream endpoint. The server will replay events from after that ID. Q: GET /api/v1/cloud/environments returns an empty array? A: Check that your Personal Access Token (PAT) has the required permissions for the target workspace. Environment access is scoped to the authenticated user’s permissions.

API Reference