Skip to main content
POST
Sessions API

Sessions API

Sessions are the top-level containers for all agent interactions. They persist state, memory, and conversation history.

Authentication

All API requests require authentication via API key:
Header: X-API-Key: sb_<your_key>
Get your API key: Dashboard → API Keys

Create Session

POST /v1/sessions Creates a new session for an agent. Sessions are isolated containers that store state, memory, and conversation history.

Request Body

Response

Example

Error Responses


Get Session

GET /v1/sessions/{session_id} Retrieves a session by ID, including current state and metadata.

Path Parameters

Response

Same structure as Create Session response.

Example

Error Responses


Get Session Context

POST /v1/sessions/{session_id}/context The most important endpoint for building agents. Returns everything your agent needs in one call:
  • Current state
  • Relevant memories (via semantic search)
  • Recent conversation turns

Path Parameters

Request Body

Response

Example


Update Session State

POST /v1/sessions/{session_id}/state Updates the session’s state. Creates a new state version for rollback capability.

Path Parameters

Request Body

Response

Returns updated session object.

Example


Rollback Session

POST /v1/sessions/{session_id}/rollback Reverts session state to a previous version. Creates a new version with the restored state.

Path Parameters

Request Body

Example


Fork Session

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.

Path Parameters

Request Body

Response

Returns new session object with metadata indicating it was forked.

Example


List Sessions

GET /v1/sessions Lists all sessions for your account, with pagination.

Query Parameters

Example


Delete Session

DELETE /v1/sessions/{session_id} Permanently deletes a session and all associated data (state, turns, memories). Warning: This action is irreversible.

Path Parameters

Example


Rate Limits

Rate limit headers (included in all responses):
  • X-RateLimit-Limit: Max requests per minute
  • X-RateLimit-Remaining: Remaining requests
  • X-RateLimit-Reset: Unix timestamp when limit resets

Webhooks

Subscribe to session events: Configure webhooks in Dashboard → Webhooks.

Best Practices

✅ Do This

  • Use get_context() for every turn (it’s optimized for agent prompts)
  • Include reasoning in state updates (helps with debugging)
  • Set appropriate TTLs (don’t keep sessions forever)
  • Use user_id for multi-tenant isolation

❌ Avoid This

  • Don’t poll for updates (use webhooks instead)
  • Don’t store sensitive data in state (use encrypted metadata)
  • Don’t create a new session per message (reuse sessions for conversations)

Next Steps


Need help? Join our Discord or email support@statebase.org