# Query Turns

Source: https://agenta.ai/docs/reference/api/query-turns

`POST /sessions/turns/query`

Base URL: `https://us.cloud.agenta.ai/api` (US cloud), `https://eu.cloud.agenta.ai/api` (EU cloud) or `$AGENTA_HOST/api` (self-hosted). Authentication: `Authorization: ApiKey YOUR_API_KEY`.

Query Turns

## Request body schema

Content type: `application/json` (required)

- `query` (object, nullable)
  - `session_id` (string, nullable)
  - `stream_id` (string (uuid), nullable)
  - `harness_kind` (string, one of: "pi_core", "claude", "codex", "mock", nullable)
  - `references` (array of object, nullable)
    - `version` (string, nullable)
    - `slug` (string, nullable)
    - `id` (string (uuid), nullable)
    - `key` (string, nullable)
- `windowing` (object, nullable)
  - `newest` (string (date-time), nullable)
  - `oldest` (string (date-time), nullable)
  - `next` (string (uuid), nullable)
  - `limit` (integer, nullable)
  - `order` (string, one of: "ascending", "descending", nullable)
  - `interval` (integer, nullable)
  - `rate` (number, nullable)

## Response schemas

### 200: Successful Response

- `count` (integer) Default: `0`.
- `turns` (array of object)
  - `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)
  - `id` (string (uuid), nullable)
  - `project_id` (string (uuid), required)
  - `session_id` (string, required)
  - `turn_id` (string (uuid), nullable)
  - `stream_id` (string (uuid), required)
  - `turn_index` (integer, required)
  - `harness_kind` (string, one of: "pi_core", "claude", "codex", "mock", required): The coding agent program a run drives. A backend declares which it supports. ``pi_core`` is Pi; ``claude`` drives Claude Code; ``codex`` drives Codex. ``mock`` drives no real coding agent at all: it is a deterministic, LLM-free, network-free stand-in for testing, selecting a named behavior the runner resolves in-process.
  - `agent_session_id` (string, nullable)
  - `sandbox_id` (string, nullable)
  - `references` (array of object, nullable)
    - `version` (string, nullable)
    - `slug` (string, nullable)
    - `id` (string (uuid), nullable)
    - `key` (string, nullable)
  - `trace_id` (string (uuid), nullable)
  - `span_id` (string, nullable)
  - `start_time` (string (date-time), nullable)
  - `end_time` (string (date-time), nullable)
  - `principal` (object, nullable)
    - `kind` (string, one of: "human", "api_key", "installation", required)
    - `id` (string (uuid), required)
  - `sender` (object, nullable)
    - `user_id` (string (uuid), nullable)
    - `external_key` (string, nullable)
  - `context` (object, nullable)
    - `run_id` (string, nullable)
    - `parent_run_id` (string, nullable)
    - `origin` (string, one of: "web", "api", "installation", "schedule", "subscription", "evaluation", "child", "calling_session", required)
    - `origin_id` (string, nullable)
  - `approved_by` (object, nullable)
    - `principal` (object, required)
    - `user_id` (string (uuid), nullable)
    - `external_key` (string, nullable)
    - `is_run_credential` (boolean) Default: `false`.
  - `usage` (object, nullable)
    - `input_tokens` (integer, nullable)
    - `output_tokens` (integer, nullable)
    - `total_tokens` (integer, nullable)
    - `cost` (number, nullable)
    - `source` (string, one of: "runner", "trace", required): Where a turn's figures came from: the trace root, or only the runner.
- … more fields: see the OpenAPI specification.

### 422: Validation Error

- `detail` (array of object)
  - `loc` (array of string | integer, required)
  - `msg` (string, required)
  - `type` (string, required)
  - `input` (any)
  - `ctx` (Context)
