Agent Session REST API#
Phoenix exposes two REST endpoints for listing and retrieving persisted agent sessions. These routes were added in PR #14711 and are implemented in src/phoenix/server/api/routers/agents.py. They are distinct from the GraphQL interface, which gates access via the CanAccessAgentSession permission class in src/phoenix/server/api/agent_helpers.py .
Both endpoints return only persisted (non-temporary, non-expired) sessions.
Endpoints#
| Method | Path | Operation ID | Description |
|---|---|---|---|
GET | /agents/{agent_id}/sessions | listAgentSessions | List sessions with cursor pagination |
GET | /agents/{agent_id}/sessions/{session_id} | getAgentSession | Get a single session with full message transcript |
List Sessions β GET /agents/{agent_id}/sessions#
Query parameters:
cursor(optional): opaque pagination cursorlimit(optional, default20, max100)
Response β ListAgentSessionsResponseBody:
data: array ofAgentSessionSummaryobjects β fields:id,title,created_at,updated_at,is_temporarynext_cursor: pagination cursor for the next page;nullif no further results
Get Session β GET /agents/{agent_id}/sessions/{session_id}#
Response β GetAgentSessionResponseBody:
data: anAgentSessionDataobject β allAgentSessionSummaryfields plusmessages, an array ofPhoenixUIMessageobjects (id,role,parts[])
Returns 404 if the session is expired or owned by another user .
Cursor-Based Pagination#
Pagination uses a keyset strategy sorted by (updated_at DESC, id DESC) for stable ordering. The cursor encodes both sort values as an opaque token . The _parse_agent_session_cursor() utility deserializes and validates the cursor; a malformed cursor returns HTTP 422.
Access Control and User Scoping#
The helper _get_request_user_id(request) extracts the authenticated user's ID from the request :
- Auth enabled β queries are filtered to
AgentSession.user_id == <request user>. Users only see their own sessions. - Auth disabled β all persisted sessions for the agent are returned.
This is applied in both the list endpoint and the single-session endpoint. The GraphQL layer enforces equivalent scoping through get_agent_session_owner_filter() in agent_helpers.py .
Testing#
- Unit tests:
tests/unit/server/agents/test_agent_session_routes.py(201 lines, new file in PR #14711) β covers pagination limits, cursor round-trips, temporary vs. persisted session filtering, and expiry handling . - Integration tests:
tests/integration/auth/test_auth.pyβ verifies that a member API key can only list/retrieve its own sessions and receives 404 for another user's sessions .
PXI CLI Integration#
The endpoints power the /sessions session picker in the pxi CLI β an inline searchable list for restoring persisted agent chats. They are consumed via the generated Phoenix client in js/packages/phoenix-cli/src/pxi/client.ts and App.tsx . The PR also introduced /new, /temporary, and /clear session lifecycle commands alongside the session picker.
Generated Clients and Schema#
The REST routes are defined in schemas/openapi.json (+241 lines) and auto-generated into typed clients :
| Target | File |
|---|---|
| Web app (TypeScript) | app/src/api/__generated__/v1.ts |
| Phoenix JS client | js/packages/phoenix-client/src/__generated__/api/v1.ts |
| Phoenix Python client | packages/phoenix-client/src/phoenix/client/__generated__/v1/__init__.py |