> For a complete page index of the Captain API documentation, fetch https://docs.captain.dev/llms.txt?excludeSpec=true

# List Slowest Queries

GET https://api.captain.dev/v2/queries/latency/slowest

The slowest queries in the window, with ids and durations only.

Sorted by duration in the analytics store, so it costs one bounded read
rather than a walk through chronological history. Pass a `request_id` to
GET /v2/queries/\{query\_id} to open the query itself.

Reference: https://docs.captain.dev/reference/queries/latency/slowest

## Request

### Query parameters

- `from` (string, optional, nullable)
- `to` (string, optional, nullable)
- `limit` (integer, optional, default: 5)
- `collection` (string, optional, nullable)
- `api_version` (string, optional, nullable)
- `rerank` (string, optional, nullable)
- `search_mode` (string, optional, nullable)
- `has_filter` (string, optional, nullable)

## Response

### 200

Successful Response

- `generated_at` (string, required)
- `window` (LatencyWindowV2, required)
- `queries` (list of SlowestQueryV2, optional)

## Errors

### 400 Bad Request Error

Missing or invalid window, filter value, or bin count.

- `code` (string, required) — Stable error code, for example `invalid_time_range`.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.

### 401 Unauthorized Error

Missing or invalid API key.

- `error` (string, required) — Error kind. `HTTP_ERROR` for errors raised by the route.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.
- `status_code` (integer, optional) — The HTTP status code.

### 403 Forbidden Error

The API key does not have query permission.

- `error` (string, required) — Error kind. `HTTP_ERROR` for errors raised by the route.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.
- `status_code` (integer, optional) — The HTTP status code.

### 422 Unprocessable Entity Error

Validation Error

- `error` (string, required) — `VALIDATION_ERROR`.
- `message` (string, required)
- `details` (list of V2QueriesLatencySlowestGetResponsesContentApplicationJsonSchemaDetailsItems, required) — One entry per invalid field, with `type`, `loc` and `msg`.
- `path` (string, required)

### 503 Service Unavailable Error

Analytics are unavailable; no metrics were computed.

- `error` (string, required) — Error kind. `HTTP_ERROR` for errors raised by the route.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.
- `status_code` (integer, optional) — The HTTP status code.

## Types

### LatencyWindowV2

- `from` (string, required) — Start of the window, inclusive (UTC).
- `to` (string, required) — End of the window, exclusive (UTC).

### SlowestQueryV2

- `collection_name` (string, required)
- `duration_ms` (integer, required)
- `occurred_at` (string, required)
- `request_id` (string, required) — Pass to GET /v2/queries/\{query\_id} to open the query. Always present.
- `query_id` (string, optional, nullable) — The query id, when the row recorded one.

### V2QueriesLatencySlowestGetResponsesContentApplicationJsonSchemaDetailsItems

## Examples

**Response**

```json
{
  "generated_at": "2026-09-08T00:04:02.118Z",
  "window": {
    "from": "2026-09-01T00:00:00Z",
    "to": "2026-09-08T00:00:00Z"
  },
  "queries": [
    {
      "collection_name": "policy_library",
      "duration_ms": 4820,
      "occurred_at": "2026-09-07T18:22:41.845Z",
      "request_id": "req_1788804161_7b41c0a9",
      "query_id": null
    },
    {
      "collection_name": "customer_forms",
      "duration_ms": 3106,
      "occurred_at": "2026-09-07T11:14:14.272Z",
      "request_id": "req_1788801254_3e92da5f",
      "query_id": "c4b662cd-aba2-4918-8346-4b975484eded"
    }
  ]
}
```

**SDK Code**

```python Python
import requests

BASE_URL = "https://api.captain.dev"
API_KEY = "your_api_key"

response = requests.get(
    f"{BASE_URL}/v2/queries/latency/slowest",
    headers={"Authorization": f"Bearer {API_KEY}"},
    params={
        "from": "2026-09-01",
        "to": "2026-09-08",
        "limit": 2,
    },
    timeout=30.0
)

if response.status_code == 200:
    for q in response.json()["queries"]:
        print(f"{q['duration_ms']:6d} ms  {q['collection_name']:24s} {q['occurred_at']}")
        # Either id opens the stored query: GET /v2/queries/{query_id}
        # accepts the request_id as well.
        print(f"        {q['query_id'] or q['request_id']}")
else:
    print(f"Error: {response.status_code}")
```

```typescript TypeScript
const BASE_URL = "https://api.captain.dev";
const API_KEY = "your_api_key";

type Slowest = {
    queries: {
        request_id: string;
        query_id: string | null;
        duration_ms: number;
        collection_name: string;
        occurred_at: string;
    }[];
};

const query = new URLSearchParams({
    from: "2026-09-01",
    to: "2026-09-08",
    limit: "2"
});

const response = await fetch(
    `${BASE_URL}/v2/queries/latency/slowest?${query}`,
    { headers: { Authorization: `Bearer ${API_KEY}` } }
);

if (response.ok) {
    const data: Slowest = await response.json();
    for (const q of data.queries) {
        console.log(`${q.duration_ms} ms  ${q.collection_name}  ${q.occurred_at}`);
        // Either id opens the stored query: GET /v2/queries/{query_id}
        // accepts the request_id as well.
        console.log(`        ${q.query_id ?? q.request_id}`);
    }
} else {
    console.error(`Error: ${response.status}`);
}
```