Complete REST API reference for managing agent sessions
X-API-Key: sb_<your_key>POST /v1/sessions
Creates a new session for an agent. Sessions are isolated containers that store state, memory, and conversation history.
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | ✅ Yes | Unique identifier for your agent (e.g., customer-support-v1) |
user_id | string | No | User identifier for multi-tenant isolation |
initial_state | object | No | Starting state (default: {}) |
metadata | object | No | Custom metadata (e.g., {"env": "prod", "version": "1.2"}) |
ttl_seconds | integer | No | Session lifetime in seconds (default: 86400 = 24h, max: 2592000 = 30 days) |
| Field | Type | Description |
|---|---|---|
id | string | Unique session ID (format: sess_<12_chars>) |
agent_id | string | Agent identifier |
user_id | string | User identifier (if provided) |
created_at | string | ISO 8601 timestamp |
updated_at | string | ISO 8601 timestamp |
state | object | Current session state |
metadata | object | Custom metadata |
memory_count | integer | Number of memories attached to this session |
turn_count | integer | Number of conversation turns |
ttl_expires_at | string | ISO 8601 timestamp when session expires |
| Status Code | Error Code | Description |
|---|---|---|
| 400 | invalid_request | Missing required fields or invalid data types |
| 401 | authentication_failed | Invalid or missing API key |
| 429 | rate_limit_exceeded | Too many requests (default: 100/min) |
| 500 | internal_error | Server error (contact support if persists) |
GET /v1/sessions/{session_id}
Retrieves a session by ID, including current state and metadata.
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Session ID (e.g., sess_a1b2c3d4e5f6) |
| Status Code | Error Code | Description |
|---|---|---|
| 404 | session_not_found | Session doesn’t exist or has expired |
| 401 | authentication_failed | Invalid API key |
POST /v1/sessions/{session_id}/context
The most important endpoint for building agents. Returns everything your agent needs in one call:
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Session ID |
| Field | Type | Required | Description |
|---|---|---|---|
query | string | No | Search query for semantic memory retrieval (usually the user’s current message) |
memory_limit | integer | No | Max memories to return (default: 5, max: 20) |
turn_limit | integer | No | Max recent turns to return (default: 10, max: 50) |
| Field | Type | Description |
|---|---|---|
state | object | Current session state |
memories | array | Relevant memories (sorted by similarity score) |
recent_turns | array | Recent conversation turns (newest first) |
POST /v1/sessions/{session_id}/state
Updates the session’s state. Creates a new state version for rollback capability.
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Session ID |
| Field | Type | Required | Description |
|---|---|---|---|
state | object | ✅ Yes | New state (replaces current state entirely) |
reasoning | string | No | Why this update was made (for debugging) |
POST /v1/sessions/{session_id}/rollback
Reverts session state to a previous version. Creates a new version with the restored state.
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Session ID |
| Field | Type | Required | Description |
|---|---|---|---|
version | integer | ✅ Yes | State version to roll back to (0 = initial state) |
POST /v1/sessions/{session_id}/fork
Creates a new session starting from a specific version of an existing session. Useful for debugging and “what-if” scenarios.
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Source session ID |
| Field | Type | Required | Description |
|---|---|---|---|
version | integer | No | State version to fork from (default: latest) |
GET /v1/sessions
Lists all sessions for your account, with pagination.
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | integer | No | Max sessions to return (default: 20, max: 100) |
starting_after | string | No | Session ID to start after (for pagination) |
agent_id | string | No | Filter by agent ID |
user_id | string | No | Filter by user ID |
DELETE /v1/sessions/{session_id}
Permanently deletes a session and all associated data (state, turns, memories).
Warning: This action is irreversible.
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Session ID to delete |
| Tier | Requests/Minute | Burst |
|---|---|---|
| Free | 100 | 200 |
| Pro | 1,000 | 2,000 |
| Enterprise | Custom | Custom |
X-RateLimit-Limit: Max requests per minuteX-RateLimit-Remaining: Remaining requestsX-RateLimit-Reset: Unix timestamp when limit resets| Event | Description |
|---|---|
session.created | New session created |
session.updated | Session state or metadata changed |
session.deleted | Session deleted |
session.expired | Session TTL expired |
get_context() for every turn (it’s optimized for agent prompts)reasoning in state updates (helps with debugging)user_id for multi-tenant isolation