Skip to main content
A session is a single running instance of an agent for a specific task. When you create a session, the platform pins the specified agent version, execution environment version, and session resources, and returns a session ID prefixed with 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.
Creating a session does not start a task. Newly created sessions start in the idle status—the agent does not run and no task events are emitted yet. We recommend opening the event stream first and then sending the first user.message; the session enters the running status only after receiving that input.

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 a POST /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 via file_id.
  • vault: Binds a vault via vault_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 via memory_store_id and sets access to read_only or read_write. Bind it at session creation; it cannot be added or modified later, but you can unbind the store via the session resources endpoints. Optional instructions provide additional guidance to the model for this binding.
  • github_repository: Specifies a GitHub repository via url, with optional checkout, mount_path, and authorization_token for private repositories; the binding cannot be added, modified, or removed after creation.
Files, vaults, and memory stores are bound by reference—file contents and credential values are not copied into the request body. GitHub repositories are cloned into the session sandbox according to their 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. Omit resources 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.
When creation succeeds, the endpoint responds with the session object. At this point 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_version is 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 ready version of the specified environment at creation time. environment_id cannot be changed once bound; if the environment is not visible, is archived, or has no ready version, 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.
To run a new task with an updated agent or execution environment configuration, create a new session. Existing sessions continue using their pinned versions.

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.
Run the examples below in two separate terminals. Subscribe to the event stream in Terminal 1 first, and then send the first message in Terminal 2; replace sesn_your_session_id with the session ID returned when you created the session. Terminal 1: Subscribe to the event stream
Terminal 2: Send the first message
After you send the message, events stream continuously in Terminal 1. As 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.