---
search:
  tags:
    - AI
    - POST
seo:
  description: >-
    Search agent threads the caller is allowed to read. Reference for the POST
    /v1/ai/chats/search endpoint in the Roboto REST API.
sidebar:
  label: Search threads legacy
  badge: POST
title: Search threads legacy
type: openapi-operation
---
Search agent threads the caller is allowed to read.

The repo enforces a filter whitelist (``thread_id``, ``title``,
``created``, ``created_by``, ``status``, ``visibility``,
``created_from_agent_id``, ``subject_id``) and a sort whitelist
(``created``). ``status`` accepts the lowercase ``AgentThreadStatus``
values (``not_started``, ``user_turn``, ``roboto_turn``,
``client_tool_turn``, ``goals_failed``); ``visibility`` accepts the
lowercase ``ThreadVisibility`` values (``private``, ``org``).

Two structural authz gates are bound from caller identity and AND-ed
onto every query — both are unreachable from the request body:

* ``org_id`` pins the result set to the caller's org.
* ``visibility = 'org' OR created_by = caller_user_id`` hides
  ``PRIVATE`` threads created by other users; the caller sees every
  ``ORG``-visible thread plus their own private rows. Roboto staff
  bypass this gate so the admin
  thread explorer continues to see every thread in an org —
  mirroring the per-row check in ``get_thread_by_id_with_access_check``.

Common UI compositions: the dataset-detail "Agent Threads" tab pins
``subject_id == <dataset_id>`` as a scope filter; the agent detail
page's "threads launched from this agent" list passes
``created_from_agent_id == <id>``.

#### Access control
 - requires_org
 - Restricted tokens need the API scope `api.everything_else`

`POST /v1/ai/chats/search`

**Request body** (`application/json`, required)

- `condition` (Condition | ConditionGroup | null)
- `limit` (integer)
- `max_results` (integer | null)
- `after` (string | null)
- `sort_by` (string | null)
- `sort_direction` (SortDirection | null)

Request body example:

```json
{
  "condition": null,
  "limit": 1000,
  "max_results": null,
  "after": null,
  "sort_by": null,
  "sort_direction": null
}
```

**Responses**

- `200` — OK
- `400` — A conversation with Roboto's AI is longer than the AI model can read at once. The conversation's messages and tool results, together with the AI's instructions, exceed the model's context window. The exception does not carry the token count or the model's limit.
- `401` — The caller's token is expired or malformed.
- `403` — The request would take the user or organization past a limit on a resource, such as AI credits.
- `404` — The request names an API route Roboto does not serve.
- `409` — The request conflicts with an existing resource, such as by giving a name another resource already has.
- `410` — The resource the request names is missing or has expired.
- `500` — Roboto reported an error that this release of the SDK cannot match to a specific exception class. Reported for an element of a :py:class:\`\~roboto.http.BatchResponse\` whose error names a code this release defines no class for, or that arrived without a code, without a message, or as text that is not an error envelope at all. It carries whatever code and message Roboto sent, so a caller handling the failure still learns what went wrong; when no message could be read, the message is the error's raw text. :py:meth:\`\~roboto.domain.devices.Device.create\_session\` raises it, and :py:meth:\`\~roboto.domain.devices.Device.create\_sessions\` lists it in the batch's :py:attr:\`\~roboto.http.BatchResponse.failed\`. The error envelope carries no status code, so \`\`http\_status\_code\`\` reports the 500 inherited from \`\`RobotoDomainException\`\` rather than the status the failure had.
- `501` — The request asks for an operation this deployment of Roboto does not provide.
- `503` — Roboto could not accept the request, such as under heavy load. Retrying later may succeed.
- `504` — Roboto ran out of time while processing the request. Retrying may succeed.
- `507` — The response to the request is larger than Roboto can send. Retrying the same request fails the same way; request less data at a time.

Response example, 200:

```json
{
  "data": {
    "items": [
      {
        "thread_id": "string",
        "created": "2019-08-24T14:15:22Z",
        "created_by": "string",
        "created_by_principal": null,
        "org_id": "string",
        "messages": [
          {
            "role": "user",
            "content": [
              {
                "text": "string"
              }
            ],
            "status": "not_started",
            "created": "2019-08-24T14:15:22Z",
            "created_by": null
          }
        ],
        "continuation_token": "string",
        "has_more": false,
        "status": "not_started",
        "activity": null,
        "title": null,
        "model_profile": null,
        "forked_from_thread_id": null,
        "forked_from_message_sequence_num": null,
        "visibility": "private",
        "created_from_agent_id": null,
        "created_from_trigger_id": null,
        "origin": null,
        "pinned_at": null,
        "goals": null,
        "tasks": null,
        "turn_notice": null
      }
    ],
    "next_token": null,
    "total_count": null
  }
}
```
