---
title: "Query Sessions"
method: POST
path: "/sessions/query"
tags: ["Sessions", "Sessions"]
---

# Query Sessions

`POST /sessions/query`

## Request body

- SessionQueryRequest
  - `session` SessionPredicatesRequest
    - `search` string, nullable
    - `liveness` SessionStreamQueryFlags
      - `is_alive` boolean, nullable
      - `is_running` boolean, nullable
      - `is_attached` boolean, nullable
    - `origins` SessionOrigin[], nullable
  - `session_ids` string[], nullable
  - `exclude` SessionExcludeRequest
    - `origins` SessionOrigin[], nullable
    - `session_ids` string[], nullable
  - `turn_references` SessionReference[], nullable
    - `version` string, nullable
    - `slug` string, nullable
    - `id` string, uuid, nullable
    - `key` string, nullable
  - `include_ended` boolean
  - `include_archived` boolean
  - `include_total` boolean
  - `expand` SessionExpansion[]
  - `windowing` Windowing
    - `newest` string, date-time, nullable
    - `oldest` string, date-time, nullable
    - `next` string, uuid, nullable
    - `limit` integer, nullable
    - `order` 'ascending' | 'descending', nullable
    - `interval` integer, nullable
    - `rate` number, nullable
  - `references` SessionReference[], nullable
    - `version` string, nullable
    - `slug` string, nullable
    - `id` string, uuid, nullable
    - `key` string, nullable
  - `search` string, nullable
  - `flags` SessionStreamQueryFlags
    - `is_alive` boolean, nullable
    - `is_running` boolean, nullable
    - `is_attached` boolean, nullable
  - `exclude_session_ids` string[], nullable
  - `origin` 'manual' | 'trigger'
  - `exclude_origin` 'manual' | 'trigger'

## Response `200`

Successful Response

- SessionsResponse
  - `count` integer
  - `total` integer, nullable
  - `sessions` SessionListItem[]
    - `created_at` string, date-time, nullable
    - `updated_at` string, date-time, nullable
    - `deleted_at` string, date-time, nullable
    - `created_by_id` string, uuid, nullable
    - `updated_by_id` string, uuid, nullable
    - `deleted_by_id` string, uuid, nullable
    - `name` string, nullable
    - `description` string, nullable
    - `id` string, uuid, nullable
    - `project_id` string, uuid, required
    - `session_id` string, required
    - `flags` SessionStreamFlags — The nest as primitive bools (alive ⊇ running ⊇ attached). resumable (alive & !running) and reattachable (running & !attached) are derived client-side, never stored.
      - `is_alive` boolean
      - `is_running` boolean
      - `is_attached` boolean
    - `tags` object, nullable
    - `meta` object, nullable
    - `turn_id` string, nullable
    - `references` SessionReference[], nullable
      - `version` string, nullable
      - `slug` string, nullable
      - `id` string, uuid, nullable
      - `key` string, nullable
    - `archived_at` string, date-time, nullable
    - `origin` 'manual' | 'trigger'
    - `trigger` SessionTrigger
      - `id` string, uuid, required
      - `kind` 'schedule' | 'subscription', required
      - `name` string, nullable
    - `delivery` SessionDelivery
      - `id` string, uuid, required
    - `last_message` SessionMessagePreview — The last thing said in a session, for a list row. A session row carried a title and a timestamp, so deciding whether a session was worth reopening meant opening it. Only `message` records are considered: `done`/`usage` are bookkeeping, `thought` is not addressed to anyone, and a `tool_call` says what the agent reached for rather than what it concluded.
      - `text` string, required
      - `source` string, nullable
      - `timestamp` string, date-time, nullable
  - `windowing` Windowing
    - `newest` string, date-time, nullable
    - `oldest` string, date-time, nullable
    - `next` string, uuid, nullable
    - `limit` integer, nullable
    - `order` 'ascending' | 'descending', nullable
    - `interval` integer, nullable
    - `rate` number, nullable

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/agenta-ai/apis/agenta-api.md) · [All operations](https://skmtc.net/agenta-ai/apis/agenta-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/agenta-ai/agenta-api/revisions/e1ffc32fa59c/schema)
