Pagination

Page through Askocto API v2 lists with the limit and cursor parameters and the nextCursor value, with a loop that reads every page.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

List endpoints in API v2 return results in pages. You ask for a page size with limit, and you move to the next page with a cursor. Cursors stay correct when new items arrive while you read, which page numbers do not.

Parameters and response

Name Type Required Description
limit integer No Items per page, from 1 to 100. Defaults to 20.
cursor string No The nextCursor value from the previous page. Leave it out for the first page.

Every list response has the same envelope:

{
  "data": [
    { "id": "agt_8f3k2m", "name": "Store support", "type": "support", "status": "live" }
  ],
  "nextCursor": "cur_a81f3c92"
}

data holds the items. nextCursor is a string while more items are available and null on the last page.

Rules for cursors

  • A cursor is opaque. Do not parse it, build it or store it for long. Pass it back exactly as you received it.
  • Send the same filters and the same limit on every request of one walk through a list.
  • An empty data array with a null cursor means the list is empty or finished.

Read one page

curl "https://api.askocto.co/v2/agents?limit=2" \
  -H "Authorization: Bearer $OCTO_API_KEY"

curl "https://api.askocto.co/v2/agents?limit=2&cursor=cur_a81f3c92" \
  -H "Authorization: Bearer $OCTO_API_KEY"

Read every page

This loop reads a whole list and works for any v2 list endpoint:

async function listAll(path) {
  const items = []
  let cursor = null

  do {
    const url = new URL(`https://api.askocto.co${path}`)
    url.searchParams.set("limit", "100")
    if (cursor) url.searchParams.set("cursor", cursor)

    const response = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.OCTO_API_KEY}` },
    })
    if (!response.ok) throw new Error(`Request failed with status ${response.status}`)

    const page = await response.json()
    items.push(...page.data)
    cursor = page.nextCursor
  } while (cursor)

  return items
}

const sources = await listAll("/v2/agents/agt_8f3k2m/sources")
const ready = sources.filter((source) => source.status === "ready")
console.log(`${ready.length} of ${sources.length} sources are ready`)

For large lists, handle each page as it arrives instead of holding everything in memory. If a call returns 429, wait for the Retry-After header before the next page, see Error handling.

v1 uses page numbers

The legacy API uses page and size and returns a total. See the v1 overview. Examples of v2 lists are List agents, List sources and List conversations.

Something unclear or missing? Tell us and we will fix the page.