When to create a session
Create a new session at the very beginning of every new process, task, or agent run. The key constraint is isolation: a session represents one continuous execution, so you must never reuse a session token across separate processes. If your agent crashes and restarts, create a new session. If it handles a new user request, create a new session.Creating a session
Send a POST request to the UASAM session endpoint with your agent key in the header. The request body is optional but you should always include ameta object — even an empty one — to leave room for task context.
Endpoint: POST http://localhost:8000/api/agent/v1/session/create/
Headers:
| Header | Value |
|---|---|
X-OTAS-AGENT-KEY | Your agent key (agent_<prefix>_<secret>) |
Content-Type | application/json |
meta field accepts arbitrary JSON. Use it to record whatever context is meaningful for the task — for example:
Using the session JWT
Store thejwt_token value from the response and pass it as the X-OTAS-AGENT-SESSION-TOKEN header on every subsequent request for this session — both in-domain requests and out-of-domain log calls.
The JWT encodes the
agent_session_id and agent_id. Brain validates this token on every event capture request, so there is no separate session activation step.Session expiry
Session JWTs are valid for 30 days from the time of creation. After expiry, requests using the token will be rejected with a401 invalid_or_expired_token response. If your agent is long-running (spanning multiple days), you should create a new session before the old one expires or at each logical task boundary.
Listing sessions
You can retrieve all sessions for a given agent using the list endpoint. This is useful for auditing, debugging, or fetching a session ID to query its events in Brain. Endpoint:GET http://localhost:8000/api/agent/v1/sessions/list/?agent_id=<uuid>
Required headers: X-OTAS-USER-TOKEN, X-OTAS-PROJECT-ID
Sessions are returned ordered by created_at descending (most recent first). Each session entry includes the session id, the agent_key_id used to create it, the created_at timestamp, and the meta object you provided at creation time.
Querying session events in Brain
Once you have a session ID, you can fetch all events captured during that session: Endpoint:GET http://localhost:8002/api/v1/agent/session/events/?session_id=<uuid>
Required headers: X-OTAS-USER-TOKEN, X-OTAS-AGENT-ID, X-OTAS-PROJECT-ID
Results are ordered by event_time ascending and are capped at 200 events by default (maximum 500 via the limit query parameter). This endpoint is the primary way to replay or inspect what your agent did during a specific run.