{
  "schema_version": 2,
  "id": "develop/ai/context-engine/agent-memory/sessions/list-sessions",
  "title": "List and sort sessions",
  "url": "https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/sessions/list-sessions/",
  "summary": "List session metadata by owner or namespace, sort results, and follow pagination.",
  "aliases": [
    "/develop/ai/context-engine/agent-memory/list-sessions/"
  ],
  "tags": [
    "docs",
    "develop",
    "ai"
  ],
  "last_updated": "2026-11-03T10:02:56-08:00",
  "page_type": "content",
  "content_hash": "c027c9b0164cefc9c1e4a3a4b3f5bd47716d55a748fa62d1c32b67ee649c2adf",
  "sections": [
    {
      "id": "code-examples",
      "title": "Code examples",
      "role": "example",
      "text": "These examples connect to Iris services using SDKs or HTTP requests with curl. Follow one language throughout each walkthrough.\n\n\nUse session listing to let a user reopen an earlier conversation. The session rows contain IDs and available owner, timestamp, and namespace metadata. They do not contain conversation events or summary text. Retrieve the selected session with `memory.conversation(owner=..., session_id=...).transcript()` (Python), `iris agent-memory sessions show`, or `GET /iris/data/v1/agent-memory/stores/{storeId}/sessions/{sessionId}` to build the agent's conversation context."
    },
    {
      "id": "choose-a-listing-operation",
      "title": "Choose a listing operation",
      "role": "content",
      "text": "| Result you need | REST endpoint | Python | CLI |\n|:----------------|:--------------|:-------|:----|\n| Every session ID for one owner | `GET /iris/data/v1/agent-memory/stores/{storeId}/sessions?ownerId=...` | `memory.sessions(owner)` | `iris agent-memory sessions list --owner` |\n| Session rows with filters, sorting, and pagination | `GET /iris/data/v1/agent-memory/stores/{storeId}/sessions` | `memory.client.list_sessions` | Not available |\n\nThe REST operation returns `items` and an optional `nextCursor`. It does not return a total count. `memory.sessions(owner)` follows every page for you and returns only the IDs.\n\nThese examples continue from the [quickstart](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/quickstart). Load the same `.env` connection values and reuse its user ID. Expand an example to copy a complete program that connects for you.\n\nEach run repeats every write in the program. Session-event writes and memory creates with a new idempotency key add new records, so run cleanup or change the identifiers before rerunning.\n\n\nTo list the quickstart user's session IDs:\n\n**Available in:** Python (Iris), cURL (Iris), CLI (Iris)\n\n##### Python (Iris)\n\n[code example]\n\n##### cURL (Iris)\n\n[code example]\n\n##### CLI (Iris)\n\n[code example]\n\n\n\nFor a user's personal conversations, set `ownerId` to the user's authenticated ID. The session owner is the first event's `actorId`. Add `namespaceId` to require an exact namespace ID as well. It does not include descendants, deprecated namespace labels, or sessions without a namespace resource. Owner and namespace matching is case-sensitive.\n\nA request without filters must set `includeAll=true`. Do not combine `includeAll=true` with either filter. Authorize store-wide or shared namespace listing in your application before making the request. A filter selects records; it does not establish the caller's right to access them."
    },
    {
      "id": "sort-and-paginate-session-rows",
      "title": "Sort and paginate session rows",
      "role": "content",
      "text": "The default is `sortBy=updatedAt` and `sortOrder=DESC`, so recent activity appears first. `sortBy` accepts `sessionId`, `createdAt`, or `updatedAt`. `sortOrder` accepts `ASC` or `DESC`. When omitted, it is ascending for `sessionId` and descending for timestamps. `limit` accepts 1–200 and defaults to 100.\n\nTo list session rows for one owner, with the most recently updated sessions first, follow every page:\n\n**Available in:** Python (Iris), cURL (Iris)\n\n##### Python (Iris)\n\n[code example]\n\n##### cURL (Iris)\n\n[code example]\n\n\n\nPass each returned `nextCursor` as `cursor`. Keep filters and sort options unchanged; the cursor is bound to them. Stop when the cursor is absent. The cursor is opaque, so URL-encode it in REST requests. Changing a filter or sort requires a new request without the old cursor.\n\nSessions stored without owner or timestamp metadata can omit `ownerId`, `createdAt`, or `updatedAt`. Handle those missing values when rendering a conversation list. A row's timestamps describe session metadata; they do not promise that background extraction or summarization has completed."
    }
  ],
  "examples": [
    {
      "id": "choose-a-listing-operation-ex0",
      "language": "python",
      "code": "for session_id in memory.sessions(OWNER_ID):\n    print(session_id)",
      "section_id": "choose-a-listing-operation"
    },
    {
      "id": "choose-a-listing-operation-ex1",
      "language": "bash",
      "code": "curl --fail-with-body --silent --show-error --get \\\n  \"$MEMORY_API/sessions\" -H \"$AUTH\" \\\n  --data-urlencode \"ownerId=$OWNER_ID\" | jq -r '.items[].sessionId'",
      "section_id": "choose-a-listing-operation"
    },
    {
      "id": "choose-a-listing-operation-ex2",
      "language": "bash",
      "code": "set -euo pipefail\n\niris agent-memory sessions list --owner quickstart-user",
      "section_id": "choose-a-listing-operation"
    },
    {
      "id": "sort-and-paginate-session-rows-ex0",
      "language": "python",
      "code": "cursor = None\nwhile True:\n    page = memory.client.list_sessions(\n        owner_id=OWNER_ID,\n        sort_by=models.SessionListSortBy.UPDATED_AT,\n        sort_order=models.SessionListSortOrder.DESC,\n        limit=20,\n        cursor=cursor,\n    )\n    for session in page.items:\n        print(session.session_id, session.updated_at, session.namespace_id)\n    cursor = page.next_cursor\n    if not cursor:\n        break",
      "section_id": "sort-and-paginate-session-rows"
    },
    {
      "id": "sort-and-paginate-session-rows-ex1",
      "language": "bash",
      "code": "CURSOR=''\nwhile :; do\n  PAGE=$(curl --fail-with-body --silent --show-error --get \\\n    \"$MEMORY_API/sessions\" -H \"$AUTH\" \\\n    --data-urlencode \"ownerId=$OWNER_ID\" \\\n    --data-urlencode 'sortBy=updatedAt' --data-urlencode 'sortOrder=DESC' \\\n    --data-urlencode 'limit=20' ${CURSOR:+--data-urlencode \"cursor=$CURSOR\"})\n  jq -c '.items[] | {sessionId, updatedAt, namespaceId}' <<< \"$PAGE\"\n  CURSOR=$(jq -r '.nextCursor // empty' <<< \"$PAGE\")\n  [ -n \"$CURSOR\" ] || break\ndone",
      "section_id": "sort-and-paginate-session-rows"
    }
  ]
}
