sesn_.
You can then use this ID to send and subscribe to events and manage the session lifecycle.
Before creating a session, prepare an agent and an available execution environment.
Session configuration
In addition to the API, you can create sessions, send tasks, monitor progress, and download results through the Console or the kha CLI. The examples below show both cURL and kha CLI commands. Send aPOST /v1/sessions request to create a session.
Only agent_id and environment_id are required in the request body:
agent_overrides customizes the configuration of the pinned agent version for the current session without modifying the agent resource or creating a new agent version.
roster can only be set when creating a session, and its entries are resolved and pinned to exact versions at creation time; passing roster when updating a session returns HTTP 400 invalid_parameter_error. The provider of model must match the session’s model provider.
Each collection field supports three states: omitting the field inherits the collection from the pinned agent version on creation (leaving the existing override unchanged on update), passing an explicit empty array clears the collection for this session on creation (clearing the override and falling back to the pinned agent version’s collection on update), and passing a non-empty array replaces the entire collection rather than merging with the existing one.
Custom tool declarations and validation rules for tools match those on an agent, with one exception for built-in toolsets: if the tools array you pass does not include an agent_toolset, the platform keeps the agent_toolset declaration from the bound agent (or the currently effective one), or prepends agent_toolset_20261101 if none exists. When updating a session, passing tools: [] clears the tools override and inherits the bound agent’s tools. Each tools list allows at most one sandbox toolset.
These settings affect only the current session.
Each object in resources uses type to specify the resource kind:
file: References an uploaded file viafile_id.vault: Binds a vault viavault_id. Bind it at session creation; it cannot be added or modified later, but you can unbind it via the session resources endpoints.memory_store: Binds a memory store viamemory_store_idand setsaccesstoread_onlyorread_write. Bind it at session creation; it cannot be added or modified later, but you can unbind the store via the session resources endpoints. Optionalinstructionsprovide additional guidance to the model for this binding.github_repository: Specifies a GitHub repository viaurl, with optionalcheckout,mount_path, andauthorization_tokenfor private repositories; the binding cannot be added, modified, or removed after creation.
url and checkout configuration.
To prepare files, vaults, memory stores, and GitHub repositories, see Files, Vaults, Memory, and GitHub Repositories.
Create a session
The following request creates a session and binds an uploaded file. Omitresources if you do not need to bind any resources; to bind vaults, memory stores, or GitHub repositories, add the corresponding configurations to the same array.
status is idle, meaning the session has been created but has not started running yet:
Versions pinned at creation
When you create a session, the platform selects and pins the following configuration:- Agent version: If
agent_versionis omitted, the platform pins the latest version available at creation time; if specified, it pins that exact version. Updating the agent later does not change the version used by this session. - Execution environment version: The platform pins the latest
readyversion of the specified environment at creation time.environment_idcannot be changed once bound; if the environment is not visible, is archived, or has noreadyversion, the creation request is rejected. - Session resources: Vault, memory store, and GitHub repository bindings can only be created with the session and cannot be added or modified later. You can unbind a vault or memory store via
DELETE /v1/sessions/{id}/resources/{resource_id}: unbinding a vault stops credential injection immediately, while unbinding a memory store takes effect on the next wake-up (the in-flight turn is unaffected). GitHub repository bindings cannot be removed after creation. Files can be added or removed after creation via the session resources endpoints; see Files. For repository configuration, see GitHub Repositories.
Start a task
After creating a session, start a task in the following order:1
Subscribe to the event stream
Call
GET /v1/sessions/{session_id}/events/stream to open an SSE connection so you receive status updates and output events once execution starts.2
Send the first message
Call
POST /v1/sessions/{session_id}/events to send a user.message event.
This request adds the task to the session input queue and triggers execution.3
Process events
Listen for
session.status, agent.message, and other events until the current turn finishes.
For event schemas and stream resumption after a disconnect, see Event Stream.sesn_your_session_id with the session ID returned when you created the session.
Terminal 1: Subscribe to the event stream
session.status, agent.message, and other events arrive, you can monitor task status and agent output. For disconnect recovery and event handling details, see Event Stream.
Next steps
Subscribe to Session Events
Open an SSE connection, send messages, and process real-time events.
Cancel, Archive, or Delete Sessions
Inspect sessions, update titles, cancel turns, or archive and delete sessions.