Skip to main content
For concepts, see Sessions and Realms.
The Rust snippets on this page use the SessionService API. Production surfaces host that service behind the runtime control plane; small standalone Rust examples may instead construct EphemeralSessionService directly.

Create a session

Multi-turn

Attach host context without merging it into the prompt

Use injected_context for ambient facts that should be retained as separate, typed transcript messages immediately before the user’s message. These entries are visible in transcript reads but excluded from semantic-memory indexing. Use transient_turn_context instead when host-regenerated facts must apply to one provider request without entering the session transcript at all.

Resume by ID or alias

CLI supports short prefix matching and relative aliases for resuming sessions.

List sessions

Read session state

Audit and restore transcript revisions

Persistent sessions retain an append-only revision graph when their transcript head is rewritten. Revision reads and restores keep the same session identity. These mutations are available over JSON-RPC and the RPC-backed SDKs, not REST. The target must be idle; running_behavior: "reject" fails with SESSION_BUSY instead of racing active work.
Read the active head with session/transcript_revision and "revision": "current". Restore a retained revision with:
session/rewrite_transcript and the corresponding SDK methods commit typed message-range replacements. A rewrite cannot mint the runtime-owned compaction_summary role, while an existing injected_context role may be preserved.

Archive a session

Interrupt a turn

Cancel an in-flight turn. Runtime-backed public interrupt handling returns a successful no-op for an existing idle session. This does not make missing or archived targets successful no-ops, and direct substrate calls differ.

Event streaming

turn_completed carries usage for one provider call while run_completed and RunResult.usage carry the session-cumulative total, and their input_tokens fields use different denominators. Read Usage accounting before aggregating either.

Model and provider selection

Switch model on a running session

A follow-up turn may replace the active model and provider without changing the session identity. The persisted auth binding is re-resolved for the new model unless the surface explicitly supplies another binding.

Config management

limits.budget sets the runtime total-token budget used at construction, distinct from the per-call output-token limit.

Realm selection

Realms scope sessions and config. Surfaces see the same state only when both the realm_id and resolved physical provider/root match. Realm is set at startup for server surfaces (RPC, REST, MCP) and per-command or per-connection for CLI and SDKs.
Without an explicit override, the CLI derives a stable workspace realm from the context root (normally the current directory) and stores it under the project-local .rkat/realms root. RPC, REST, MCP, and SDK connections create a new opaque realm unless the caller supplies one.

Next step