Create Session
/v1/agents/sessionsCreate a Session for a saved Agent version, or for an inline Agent defined in the request. The Agent configuration, Skill versions, and MCP connections are frozen for the life of the Session. Sessions always run in SandBase's hosted cloud, so there is no execution environment to choose. With stream=true and an initial input, the response is a 201 Server-Sent Events stream of the first turn instead of a JSON Session. Execution admission (balance and organization status) is checked here. The OpenAI SDK requires an environment argument; see OpenAI compatibility (/agents/openai-compatibility).
Headers
Optional. When omitted the service generates one, so a retried request can create a duplicate. Send your own stable key for retries.
Request body
Strict JSON object.
Saved Agent ID (agt_ prefix). The Agent must be active with projection_status ready. Send agent_id, agent, or both.
Agent configuration. Accepted fields are model, instructions, runtime_profile (codex, claude, or mcode; default codex), service_tier, tools, text, reasoning, and multi_agent, validated as in Create Agent. Without agent_id it defines an inline Agent and model is required; inline Agents carry no Skills or MCP connections. With agent_id, each field you send replaces that field of the saved version for this Session only. Unknown fields return 400.
Agent version. Defaults to the current version. Not allowed with an inline Agent.
Session title.
Optional first input: a string, or an array with exactly one message, e.g. [{"role":"user","content":[{"type":"input_text","text":"…"}]}]. A bare object returns 400.
Model override. agent.model is the OpenAI SDK form; when both are sent they must match.
Up to 16 string pairs.
When true, requires a non-empty input and returns 201 with a text/event-stream body. Events use the Stream events format (event: <type>, data: <json>); the first, agent.session.created, carries the Session snapshot, followed by the turn's item and output events. Validation, admission, and other errors before the stream starts return the normal JSON error. Default false.
OpenAI SDK compatibility only. Omit it in direct HTTP calls; {"type":"openai_hosted"} is accepted and any other type returns 400.
Model credential. Omit to use your calling API key. {"type":"custom","base_url":"https://…","api_key":"…"} calls your own OpenAI-compatible endpoint. Write-only.
Session object
Returned by create, get, update, rename, archive, and unarchive.
Session ID with the ses_ prefix.
Execution status: idle, in_progress, or failed. requires_action is not supported yet and surfaces as 502 executor_contract_error.
active or archived. Archived Sessions reject input.
Public failure with code, message, action, and optional retryable.
Frozen Agent version and effective model.
OpenAI-shaped snapshot of the effective Agent configuration, and token usage (null until a turn reports usage).
Origin of the Session. Sessions created with POST /v1/agents/sessions report direct and a null source_id.
Compare-and-set token for rename, archive, and unarchive.