> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olira.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Query population logs

> Returns a LogQuery builder scoped to the whole organization or an explicit patient cohort.

```python theme={null}
olira.population_logs(patient_ids: list[str] | None = None) -> LogQueryResult
```

**Requires scope:** `sdk:state-read`

Omit patient\_ids (or pass None) for org-wide queries; pass a list to restrict to a cohort. All chainable builder methods are identical to logs — see that entry.

## Parameters

<ParamField body="patient_ids" type="list[str] | None" default="None">
  Cohort of patient ids. None = whole org. Omitting queries all patients org-wide — use filters and limits when running at scale.
</ParamField>

## Returns

`LogQueryResult` — Same shape as logs — call .execute() or another terminal to run.

<ResponseField name="count" type="int">
  Total rows matched.
</ResponseField>

<ResponseField name="rows" type="list[dict]">
  Log dicts or aggregated dicts.
</ResponseField>

<ResponseField name="organization_id" type="str | None">
  Echo of the org id.
</ResponseField>

<ResponseField name="patient_id" type="str | None">
  Null for population queries.
</ResponseField>

## Raises

| Exception         | When                                                                                                                  |
| ----------------- | --------------------------------------------------------------------------------------------------------------------- |
| `ValidationError` | Unknown operator (client-side) or HTTP 422 from server.                                                               |
| `AuthError`       | HTTP 401 or 403 — invalid API key or insufficient OAuth scope for this endpoint.                                      |
| `ServerError`     | HTTP 409 (e.g. conflicting external identifier) or repeated 5xx after retries; includes status\_code when applicable. |
| `RateLimitError`  | HTTP 429 — rate limited; check retry\_after (seconds).                                                                |
| `NetworkError`    | Connection timeout, DNS failure, or read error after retries.                                                         |

<RequestExample>
  ```python Python theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")

  # Whole org
  rows = (
      olira.population_logs()
          .eq("type", "health_metric")
          .order("timestamp", desc=True)
          .limit(50)
          .execute()
  )
  print(rows.count)

  # Explicit cohort + aggregation
  agg = (
      olira.population_logs(patient_ids=["8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82", "other-patient-id"])
          .group_by("type")
          .count_agg("n")
          .execute()
  )
  for row in agg:
      print(row["type"], row["n"])
  ```

  ```http HTTP theme={null}
  POST /v1/state/logs/query
  Authorization: Bearer YOUR_API_KEY
  Content-Type: application/json

  {
    "filter": [{"field": "type", "op": "eq", "value": "health_metric"}],
    "order": [{"field": "timestamp", "desc": true}],
    "limit": 50
  }
  ```
</RequestExample>

<ResponseExample>
  ```python 200 theme={null}
  LogQueryResult(
      count=3,
      rows=[
          {"id": "log-a", "type": "health_metric", "timestamp": "2026-01-06T00:00:00Z", "payload": {...}},
          {"id": "log-b", "type": "health_metric", "timestamp": "2026-01-05T00:00:00Z", "payload": {...}},
          {"id": "log-c", "type": "health_metric", "timestamp": "2026-01-01T00:00:00Z", "payload": {...}},
      ],
      patient_id=None,
      organization_id="org-001",
  )
  ```

  ```json 401 theme={null}
  {
    "error": true,
    "status_code": 401,
    "error_type": "authentication_error",
    "message": "Could not validate credentials",
    "details": [
      {
        "type": "authentication_error",
        "message": "Could not validate credentials"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 403 theme={null}
  {
    "error": true,
    "status_code": 403,
    "error_type": "authorization_error",
    "message": "Insufficient OAuth scope for this endpoint",
    "details": [
      {
        "type": "authorization_error",
        "message": "Insufficient OAuth scope for this endpoint"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 404 theme={null}
  {
    "error": true,
    "status_code": 404,
    "error_type": "not_found_error",
    "message": "Patient not found",
    "details": [
      {
        "type": "not_found_error",
        "message": "Patient not found"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 422 theme={null}
  {
    "error": true,
    "status_code": 422,
    "error_type": "validation_error",
    "message": "Request validation failed (1 error)",
    "details": [
      {
        "type": "missing",
        "message": "Field required",
        "field": "patient_id",
        "location": ["body", "patient_id"],
        "input_value": null
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 429 theme={null}
  {
    "error": true,
    "status_code": 429,
    "error_type": "server_error",
    "message": "Rate limit exceeded",
    "details": [
      {
        "type": "rate_limit",
        "message": "Too many requests; retry after backoff"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 500 theme={null}
  {
    "error": true,
    "status_code": 500,
    "error_type": "internal_server_error",
    "message": "An internal server error occurred",
    "details": [
      {
        "type": "internal_server_error",
        "message": "An unexpected error occurred while processing your request"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```
</ResponseExample>
