> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Data freshness (last swaps)

> Check how recently ChainQuery indexed a swap on each chain. Returns 503 when any chain is stale.

Reports, for each chain you ask about, the time of the most recent indexed swap (its block time) and how far behind now that is. Use it to decide whether data is fresh enough before relying on it, or to monitor ChainQuery from your own alerting.

> [!NOTE]
>
> This endpoint lives at the **host root**, not under `/api/v1`: `https://api.example.com/health/last-swaps`. Whether it is reachable on the public host is still being confirmed. If you get a `404` there, the route is not exposed yet.

## How it works

For each chain in `chains`:

1. Find the newest indexed swap from the last `lookbackMinutes`.
2. If there is none, the chain is `stale`, with `lastSwapAt` and `lagMinutes` set to `null`.
3. Otherwise `lagMinutes` is the time since that swap, in minutes rounded to one decimal. The chain is `stale` if `lagMinutes` is **greater than** `toleranceMinutes`, otherwise `ok`.

`ok` is `true` only when every chain is `ok`. When any chain is stale, the endpoint answers **`503`** with the full report in `details`, so a plain HTTP status check is enough for uptime monitors.

Chain ids are not checked against the supported chains. An id ChainQuery doesn't index simply has no swaps and is reported as `stale`.

> [!TIP]
>
> Quiet chains can go several minutes without a swap. Raise `toleranceMinutes` (and `lookbackMinutes`, which must be at least as large) for chains with low activity to avoid false alarms.

## Query parameters

**chains** `string` *required*

Comma-separated chain ids, each with or without the `evm:` prefix: `1,8453` or `evm:1,evm:8453`. At least one id; each must be a positive integer.

**toleranceMinutes** `number` (default: 5)

Maximum lag, in minutes, for a chain to count as `ok`. Must be greater than 0; decimals are allowed.

**lookbackMinutes** `number` (default: 15)

How far back, in minutes, to look for the latest swap. Must be greater than 0 and greater than or equal to `toleranceMinutes`.

## Response

**status** `"success"`

`success` when every chain is fresh. When any chain is stale the response is a `503` error instead; see [Errors](#errors).

**data** `LastSwapsOutput`

**LastSwapsOutput**

**ok** `boolean`

`true` when every chain is `ok`. Always `true` in a `200` response.

**toleranceMinutes** `number`

The tolerance used.

**lookbackMinutes** `number`

The lookback used.

**chains** `object[]`

One entry per requested chain, in request order.

**chain**

**chainId** `number`

Chain id as a **number** (for example `1`). Unlike most endpoints, this is not the `evm:1` string form.

**lastSwapAt** `string | null`

Time of the newest indexed swap within the lookback, ISO 8601 (UTC). `null` if there was none.

**lagMinutes** `number | null`

Minutes since `lastSwapAt`, rounded to one decimal. `null` if there was no swap within the lookback.

**status** `"ok" | "stale"`

`stale` if there was no swap within the lookback or `lagMinutes` is greater than `toleranceMinutes`; otherwise `ok`.

## Errors

| Status | `code` | When |
| - | - | - |
| 400 | `INVALID_PARAMETERS` | `chains` is missing or contains an id that is not a positive integer (the field is indexed, for example `chains.1`); a tolerance or lookback is not greater than 0; or `lookbackMinutes` is smaller than `toleranceMinutes` (`lookbackMinutes: must be >= toleranceMinutes`). |
| 503 | `SERVICE_UNAVAILABLE` | At least one chain is stale. Message: `Swaps are stale`. `details` holds the full report, with the same shape as `data` above. |
| 500 | `INTERNAL_ERROR` | Unexpected server error. |

```bash cURL theme={null}
curl "https://api.example.com/health/last-swaps?chains=1,8453"
```

```bash cURL (custom thresholds) theme={null}
curl "https://api.example.com/health/last-swaps?chains=evm:1,evm:8453,evm:56&toleranceMinutes=10&lookbackMinutes=30"
```

```javascript JavaScript theme={null}
const params = new URLSearchParams({ chains: "1,8453", toleranceMinutes: "5" });

const res = await fetch(`https://api.example.com/health/last-swaps?${params}`);
const body = await res.json();

// 200 → body.data; 503 → body.details holds the same report
const report = res.ok ? body.data : body.details;
for (const c of report?.chains ?? []) {
  console.log(c.chainId, c.status, c.lagMinutes);
}
```

```json 200 theme={null}
{
  "status": "success",
  "data": {
    "ok": true,
    "toleranceMinutes": 5,
    "lookbackMinutes": 15,
    "chains": [
      { "chainId": 1, "lastSwapAt": "2026-12-03T10:14:48.000Z", "lagMinutes": 0.2, "status": "ok" },
      { "chainId": 8453, "lastSwapAt": "2026-12-03T10:14:54.000Z", "lagMinutes": 0.1, "status": "ok" }
    ]
  }
}
```

```json 503 theme={null}
{
  "status": "error",
  "statusCode": 503,
  "code": "SERVICE_UNAVAILABLE",
  "message": "Swaps are stale",
  "details": {
    "ok": false,
    "toleranceMinutes": 5,
    "lookbackMinutes": 15,
    "chains": [
      { "chainId": 1, "lastSwapAt": "2026-12-03T10:14:48.000Z", "lagMinutes": 0.2, "status": "ok" },
      { "chainId": 8453, "lastSwapAt": null, "lagMinutes": null, "status": "stale" }
    ]
  }
}
```

```json 400 theme={null}
{
  "status": "error",
  "statusCode": 400,
  "code": "INVALID_PARAMETERS",
  "message": "lookbackMinutes: must be >= toleranceMinutes",
  "details": [
    { "field": "lookbackMinutes", "message": "must be >= toleranceMinutes" }
  ]
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.