idle; send events to start work.
Session Status Lifecycle
A Session is a state machine. Thestatus field on a Session resource takes one of the following values:
| Status | Description | Transitions to |
|---|---|---|
idle | Session is idle and ready to receive a message | running, rescheduling, terminated |
running | Agent is processing a turn | idle, rescheduling, terminated |
rescheduling | The underlying runtime is being rescheduled; the Session is unavailable until it returns to idle | idle, terminated |
terminated | Session has been terminated (final state) | — |
status field:
- Archived: signalled by a non-null
archived_attimestamp. Thestatusvalue itself does not change toarchived— the Session remains readable but rejects new events. - Cancel response: the
POST /api/v1/cloud/sessions/{id}/cancelendpoint always returns a fixed body literal"status": "canceling". This is a response shape, not a Session status — the persistedstatusreverts toidleonce the turn aborts.
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.rescheduling
The runtime may temporarily move into
rescheduling while the Session is being rescheduled; it returns to idle once recovery completes.Cancel Semantics
- Cancel on
idle: No-op. Returns HTTP200and the status staysidle. - Cancel on
running: Interrupts the Agent. Returns HTTP202. The Session transitions tocanceling, then back toidleonce the turn aborts. - After cancel: The Session remains reusable — send the next
user.messageto 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 auser.message to a Session that is currently running, the API returns HTTP 409:
session.status_idle before sending the next message, or cancel the current turn first.
Create a Session
Create a Session with an existingagent and environment_id:
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 theresources array:
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
Senduser.message events through the Events API. content must be a non-empty array of content blocks:
{"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:id, event, and data. The stream endpoint supports the Last-Event-ID header for reconnection replay; event type query filters are not currently supported.
To receive incremental streaming events, set incremental_streaming_enabled: true when creating the Session. The stream can then include agent.message_start, agent.content_block_delta, and related incremental events before the final full agent.message. See Incremental streaming for a quick verification flow.
Use the list endpoint for history and pagination:
data and next_page.
Read and Update Sessions
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 publicsession_thread shape and do not include legacy thread fields such as role, name, agent_id, agent_version, or stop_reason.
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:{"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:- Send a
user.messageevent. - Listen to the SSE stream for updates.
- Wait for the
session.status_idleevent. - 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
- Pin Agent versions — In production, always create Sessions with
{"id": ..., "type": "agent", "version": ...}so Agent updates do not change Session behavior unexpectedly. - Use metadata — Record business context (task ID, trigger source, etc.) in the
metadatafield for traceability and debugging. - Cancel promptly — Cancel Sessions you no longer need to free compute resources.
FAQ
Q: What happens if I send a message to arunning 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.