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

# Troubleshoot pagination and next_cursor

> Fix 0xArchive paging that stops early, repeats rows, or never ends: has_more, next_cursor, page_limit, window boundaries, dedupe keys, and CVD across pages.

Fix a paging loop that stops early, returns duplicate rows, or rejects its cursor. Every cursor-paged route follows one rule: while `meta.has_more` is `true`, send `meta.next_cursor` back as `cursor` with every other parameter unchanged. Most paging bugs break that rule or split a long range into windows that overlap.

## Symptoms

* The loop stops before the window is done.
* The same rows appear twice in the output.
* A request fails with `400` `invalid_cursor`.
* A page returns fewer rows than the `limit` you sent.
* Cumulative volume delta (CVD) jumps at regular points in a joined series.

## Match the symptom to the cause

| Symptom | Cause and fix |
| - | - |
| Loop stops early | It stopped on a short page. Stop only when `meta.has_more` is `false`; a short page can still have more to come, and the last page after a full one can be empty |
| `400` `invalid_cursor` | The cursor was edited, built by hand, or sent with different filters. Pass `meta.next_cursor` back unchanged with the same filters, or restart without a cursor |
| Rows from the wrong place | A cursor sent with a different symbol or window is not always refused. Keep `start`, `end`, `interval`, the symbol and every filter fixed for the whole chain |
| Fewer rows than `limit` on every page | `limit` is above the route's ceiling. A larger value returns `page_limit` rows; read `page_limit` from [capabilities](https://docs.0xarchive.io/capabilities.md) |
| Duplicate rows | Adjacent windows share a boundary, or a retry overlapped a page. Start each window 1 ms after the previous end, and dedupe on a key that matches the row grain |
| CVD jumps at page edges | `cumulative_delta` restarts on every page. Rebuild it from `delta` after joining pages |

## Follow the cursor unchanged

A rejected cursor names the fix in its message:

```json theme={"theme":"github-dark"}
{
  "code": 400,
  "error": "Failed to deserialize query string: cursor: invalid cursor: pass back meta.next_cursor unchanged, or restart without a cursor",
  "error_code": "invalid_cursor",
  "param": "cursor",
  "request_id": "82553f27-48a8-4168-8286-8819f4c61dcf",
  "success": false
}
```

Store the exact cursor string with the window and filters it belongs to. Never parse, compare, or construct cursors; their encoding differs by route. [Pagination](https://docs.0xarchive.io/rest-api/pagination.md) has the full contract and a single-window loop.

## Split long ranges without overlap

The Hyperliquid trades route returns rows at both `start` and `end`, so a window that starts at the previous window's `end` repeats the rows at that millisecond. Start each window 1 ms later. Hyperliquid trades also return two rows per trade, one per side, sharing one `trade_id`, so a dedupe key of `trade_id` alone drops half the fills. Key on `trade_id` and `side`.

This loop pulls the last hour of yesterday (UTC), a window every plan serves, in four 15-minute windows:

```python theme={"theme":"github-dark"}
import os
from datetime import datetime, timezone
import requests

url = "https://api.0xarchive.io/v1/hyperliquid/trades/BTC"
headers = {"X-API-Key": os.environ["OXARCHIVE_API_KEY"], "0xArchive-Version": "2026-10-01"}

midnight = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
end = int(midnight.timestamp() * 1000) - 1  # Free serves through yesterday (UTC)
start = end - 3_600_000 + 1                 # one hour earlier
window = 15 * 60_000                        # 15-minute windows

rows, seen = [], set()
w_start = start
while w_start <= end:
    w_end = min(w_start + window - 1, end)  # windows never share a millisecond
    params = {"start": w_start, "end": w_end, "limit": 10000}
    while True:
        response = requests.get(url, headers=headers, params=params, timeout=30)
        response.raise_for_status()             # a 403 body names its error_code
        page = response.json()
        for row in page["data"]:
            key = (row["trade_id"], row["side"])   # one row per side of each trade
            if key not in seen:
                seen.add(key)
                rows.append(row)
        if not page["meta"]["has_more"]:
            break
        params["cursor"] = page["meta"]["next_cursor"]
    w_start = w_end + 1

print(len(rows), "rows,", len({r["trade_id"] for r in rows}), "trades")
```

The row count is twice the trade count. Persist the last `next_cursor` per window so a stopped run resumes inside the window instead of starting it again.

## Rebuild running totals across pages

On the CVD routes, `cumulative_delta` runs from the first bucket of each response. A response that is one page of several says so in `meta.notice`:

```json theme={"theme":"github-dark"}
"notice": "cumulative_delta runs from the first bucket of this page; to join pages, rebuild it from delta"
```

Join the pages first, then recompute the total from `delta`:

```python theme={"theme":"github-dark"}
import os
from datetime import datetime, timezone
import requests

url = "https://api.0xarchive.io/v1/hyperliquid/cvd/BTC"
headers = {"X-API-Key": os.environ["OXARCHIVE_API_KEY"], "0xArchive-Version": "2026-10-01"}
midnight = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
end = int(midnight.timestamp() * 1000) - 1  # Free serves through yesterday (UTC)
start = end - 86_400_000 + 1                # all of yesterday
params = {"start": start, "end": end, "interval": "1m", "limit": 500}

buckets = []
while True:
    response = requests.get(url, headers=headers, params=params, timeout=30)
    response.raise_for_status()
    page = response.json()
    buckets.extend(page["data"])
    if not page["meta"]["has_more"]:
        break
    params["cursor"] = page["meta"]["next_cursor"]

running = 0.0
for b in buckets:
    running += b["delta"]
    b["cumulative_delta"] = running            # one total across every page

print(len(buckets), "buckets, final CVD", round(running, 2))
```

The HIP-3 CVD route pages the same way.

## Verify the fix

* The final page has `meta.has_more` set to `false` and no `meta.next_cursor`.
* Your dedupe set removes nothing on a clean run with non-overlapping windows; anything it removes points to an overlap or a retried page.
* The joined CVD series has no reset at page boundaries.
* You kept `meta.request_id` for every page.

## Related

* [Pagination](https://docs.0xarchive.io/rest-api/pagination.md): the cursor contract and resumable backfills
* [Build a reliable client](https://docs.0xarchive.io/rest-api/reliability.md): bounded retries and request-ID logging around the loop
* [Limits and throughput](https://docs.0xarchive.io/guides/limits-and-throughput.md): worker, page, and retry budgets for one job
* [Troubleshoot missing history and history limits](https://docs.0xarchive.io/troubleshooting/history-limits.md): when the window itself is too wide or too old

## Next step

**Keep a stream running through disconnects**

If your job also follows a live stream, restore its subscriptions and fill what it missed after every reconnect.

[Fix reconnects](https://docs.0xarchive.io/troubleshooting/reconnect-and-replay.md)


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