Skip to main content
List endpoints return a single page plus a pagination block on the response envelope:
const { data, pagination } = await client.markets.getMarkets({ limit: 100 });

pagination?.has_more;
pagination?.pagination_key;
You can walk pages manually by feeding pagination_key into the next call, or use the paginate helper to iterate through every item as a stream.

paginate

paginate(fetcher, params, pageSize?) is an async generator that lazily pulls each page and yields individual items. It terminates when the server reports has_more: false or returns a null pagination_key.
import { StructClient, paginate } from "@structbuild/sdk";

const client = new StructClient({ apiKey: "sk_live_xxx" });

for await (const market of paginate(
  (params) => client.markets.getMarkets(params),
  { tags: "politics" },
  100,
)) {
  console.log(market.slug, market.last_price);
}
ArgumentTypeDescription
fetcher(params) => Promise<HttpResponse<T[]>>A namespace method bound to the client.
paramsbase params objectEverything except limit and pagination_key, which are managed by the helper.
pageSizenumberOptional page size. Defaults to 100.
Any list-style namespace method works:
for await (const trade of paginate(
  (params) => client.markets.getTrades(params),
  { condition_ids: "0xabc..." },
)) {
}

for await (const event of paginate(
  (params) => client.events.getEvents(params),
  { tags: "politics" },
)) {
}

for await (const trader of paginate(
  (params) => client.trader.getGlobalPnl(params),
  {},
)) {
}

Early termination

You can stop iterating at any time. Exiting the for await loop stops fetching the next page, so you only pay for what you read.
let count = 0;

for await (const trade of paginate(
  (params) => client.markets.getTrades(params),
  { condition_ids: "0xabc..." },
)) {
  if (++count >= 500) break;
}

Manual pagination

If you prefer to walk pages yourself (for example, to render a paginated UI), skip the helper and drive the cursor directly:
let cursor: string | number | undefined;

while (true) {
  const page = await client.markets.getMarkets({
    limit: 100,
    pagination_key: cursor,
  });

  render(page.data);

  if (!page.pagination?.has_more || page.pagination.pagination_key == null) break;
  cursor = page.pagination.pagination_key;
}
Last modified on April 14, 2026