# Query stored documents

Source: https://docs.vlayers.ai/reference/hosting/query-store-documents

`POST /v1/agents/{id}/store/{collection}/query` · scope `workspace:read`

Finds documents by the fields the manifest marks indexed: equality on any of them, ordered by one, a page at a time. A field that is not indexed is refused with 422 `field_not_indexed`; a field kept as a hash can be matched but not ordered.

Requires an API key with the `workspace:read` scope.

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | string | yes | The agent id. Example: `"0192f5c2-6f7a-7b9c-8d1e-2f3a4b5c6d78"` |
| `collection` | path | string | yes | The collection id. Example: `"orders"` |
| `where` | body | object | no | Equality on indexed fields; every one must match. |
| `orderBy` | body | object | no | An indexed field to order by, and `asc` or `desc`. |
| `limit` | body | integer | no | How many documents, 1-100. Default 50. |
| `cursor` | body | string | no | The `nextCursor` of the previous page. |

## Request

cURL:

```bash
curl -X POST "https://api.vlayers.ai/v1/agents/$AGENT_ID/store/$COLLECTION/query" \
  -H "Authorization: Bearer $VOICELAYER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "where": {
      "status": "open"
    },
    "limit": 20
  }'
```

TypeScript:

```ts
import { VoiceLayer } from '@voicelayer/api';

const voicelayer = new VoiceLayer();

const { documents } = await voicelayer.hosting.queryStoreDocuments('<agent-id>', '<collection>', {
  where: { status: 'open' },
  limit: 20
});
console.log(documents);
```

Python:

```python
from voicelayer import VoiceLayer

vl = VoiceLayer()

result = vl.hosting.query_store_documents(
    "<agent-id>",
    "<collection>",
    where={
        "status": "open",
    },
    limit=20,
)
print(result.documents)
```

## Response `200`

```json
{
  "documents": [
    {
      "collection": "orders",
      "id": "order-1001",
      "value": {
        "status": "open",
        "total": 42
      },
      "updatedAt": "2026-10-20T15:04:05.000Z"
    }
  ],
  "nextCursor": null
}
```
