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
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
Multi-turn
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
Attach host context without merging it into the prompt
Useinjected_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.
- JSON-RPC
- REST
- Python
- TypeScript
Resume by ID or alias
CLI supports short prefix matching and relative aliases for resuming sessions.List sessions
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
Read session state
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
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.
- JSON-RPC
- Python
- TypeScript
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
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
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.- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
Event streaming
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
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
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
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.- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
Config management
- CLI
- JSON-RPC
- REST
- MCP
- Python
- TypeScript
- Rust
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 therealm_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.- CLI
- JSON-RPC server
- REST server
- MCP server
- Python
- TypeScript
