Pagination and filtering
Unbounded collections use opaque keyset cursors rather than offsets or page numbers. Use this contract to continue a list safely and to distinguish backward transcript paging from forward polling.
Contract
A standard page is { data, nextCursor }. Pass a non-null nextCursor back
as cursor only to the same endpoint with the same Tenant, filters, and
ordering. null means there is no further page in the requested direction.
Do not decode, edit, or reuse a cursor across collections; invalid cursors
return 400 invalid_request.
Resource lists are newest-first according to their owning keyset: Agent
Versions by Version number, Tasks by updatedAt, Memories by the
(createdAt, id) key, and other cursored resources by their documented
descending time key. Transcript endpoints return the newest page first but
order messages chronologically inside each page.
| Collection | SDK method | REST operation | Response cursor fields | Page size | Filters |
|---|---|---|---|---|---|
| Agents | agents.list | list-agents | none | bounded; no public limit | userId |
| Agent Versions | agents.listVersions | list-agent-versions | nextCursor | default 50, max 200 | — |
| API keys | apiKeys.list | list-api-keys | none | bounded; no public limit | — |
| Providers | providers.list | list-providers | none | bounded; no public limit | — |
| MCP Connections | mcpConnections.list | list-mcp-connections | none | bounded; no public limit | — |
| MCP Attachments | agents.listMcpAttachments | list-agent-mcp-attachments | none | bounded; no public limit | owning Agent path |
| Prompts | prompts.list | list-prompts | none | bounded; no public limit | userId |
| Skills | skills.list | list-skills | none | bounded; no public limit | filter, userId |
| Sessions | sessions.list | list-sessions | nextCursor | default 50, max 200 | userId |
| Session messages | sessions.messages | list-session-messages | nextCursor, latestCursor | default 50, max 200 | cursor or after |
| Sandboxes | sandboxes.list | list-sandboxes | nextCursor | default 50, max 200 | userId |
| Artifacts | artifacts.list | list-artifacts | nextCursor | fixed 50; no public limit | sessionId, userId, includeDeleted |
| Memories | memories.list | list-memories | nextCursor | default 50, max 100 | userId, search |
| Tasks | tasks.list | list-tasks | nextCursor | default 50, max 200 | agentId, userId |
| Task runs | tasks.listRuns | list-task-runs | nextCursor | default 50, max 200 | owning Task path |
| Task run messages | tasks.runMessages | list-task-run-messages | nextCursor, latestCursor | default 50, max 200 | cursor or after |
| Usage | usage.get, getForAgent | get-usage, get-agent-usage | none | not cursored; Session top-N default 50, max 200 | dates, Agent, Session, Attribution, grouping |
Bounded named-array responses do not expose cursors. No list surface exposes offset, total-count, or generic sort.
Session and Task-run message responses add latestCursor:
cursorwalks backward to older messages.afterreads newer messages after a tail position.- The two parameters are mutually exclusive; REST validation rejects both.
- When
datais non-empty, uselatestCursoras the nextaftervalue even ifnextCursoris null. - In forward mode, pass a non-null
nextCursorback asafterto continue the same multi-page result.latestCursorrecords the observed tail for the next poll after the forward result has been drained.
For every supported userId filter, omission includes all Attribution values,
"" selects tenant-level resources, and a non-empty value selects that
tenant-user partition. Attribution remains data, not access control.
Usage from and to are paired inclusive UTC dates. With neither, the query
uses the last 30 days ending today; the bounds may differ by at most 31 days.
groupBy defaults to day and also supports agent, model, session, and
user. sessionId: "" filters stateless Turns; response buckets represent
that sentinel as sessionId: null. Tenant-level groupBy=user buckets keep
userId: "".
includeDeleted is specific to Artifacts and defaults to false. Deleted
Sessions and Tasks do not become visible through that filter. Full-text
search is specific to Memories.
Examples
Page through Sessions until the backward cursor is exhausted:
let cursor: string | undefined;
do {
const page = await client.sessions.list(agentId, { cursor, limit: 100 });
for (const session of page.data) {
console.log(session.id);
}
cursor = page.nextCursor ?? undefined;
} while (cursor);Bootstrap from a backward read, persist its non-null tail, then poll forward.
Only a nextCursor returned by a forward request is passed back as after:
const bootstrap = await client.tasks.runMessages(taskId, runId, { limit: 50 });
for (const message of bootstrap.data) console.log(message);
if (bootstrap.latestCursor === null) {
throw new Error("The Task run has no transcript tail yet");
}
await saveTail(bootstrap.latestCursor);
let after: string | undefined = bootstrap.latestCursor;
do {
const page = await client.tasks.runMessages(taskId, runId, {
after,
limit: 50,
});
for (const message of page.data) console.log(message);
if (page.latestCursor !== null) await saveTail(page.latestCursor);
after = page.nextCursor ?? undefined;
} while (after);Filter tenant-level usage and keep overall totals separate from top-N buckets:
const usage = await client.usage.get({
from: "2026-07-01",
to: "2026-07-20",
userId: "",
groupBy: "session",
limit: 25,
});
console.log(usage.totals.requestCount, usage.buckets);Used by
- Sessions and Turns
- Tasks and schedules
- Usage and quotas
- Build a chat endpoint
- Run a background Task
- Monitor usage and quotas
Source of truth
packages/core/src/api.tspackages/core/src/api.test.tspackages/core/src/entities/agents.tspackages/core/src/entities/apikeys.tspackages/core/src/entities/providers.tspackages/core/src/entities/mcp-connections.tspackages/core/src/entities/prompts.tspackages/core/src/entities/skills.tspackages/core/src/entities/sessions.tspackages/core/src/entities/sandboxes.tspackages/core/src/entities/artifacts.tspackages/core/src/entities/memories.tspackages/core/src/entities/tasks.tspackages/core/src/entities/usage.tspackages/sdk/src/resources/agents.tspackages/sdk/src/resources/agents.test.tspackages/sdk/src/resources/apikeys.tspackages/sdk/src/resources/apikeys.test.tspackages/sdk/src/resources/providers.tspackages/sdk/src/resources/providers.test.tspackages/sdk/src/resources/mcp-connections.tspackages/sdk/src/resources/mcp-connections.test.tspackages/sdk/src/resources/prompts.tspackages/sdk/src/resources/prompts.test.tspackages/sdk/src/resources/skills.tspackages/sdk/src/resources/skills.test.tspackages/sdk/src/resources/sessions.tspackages/sdk/src/resources/sessions.test.tspackages/sdk/src/resources/sandboxes.tspackages/sdk/src/resources/sandboxes.test.tspackages/sdk/src/resources/artifacts.tspackages/sdk/src/resources/artifacts.test.tspackages/sdk/src/resources/memories.tspackages/sdk/src/resources/memories.test.tspackages/sdk/src/resources/tasks.tspackages/sdk/src/resources/tasks.test.tspackages/sdk/src/resources/usage.tspackages/sdk/src/resources/usage.test.tsservers/api/src/routes/sessions/list.tsservers/api/src/routes/sessions/list.test.tsservers/api/src/routes/sessions/list-messages.tsservers/api/src/routes/sessions/list-messages.test.tsservers/api/src/routes/artifacts/list.tsservers/api/src/routes/artifacts/list.test.tsservers/api/src/routes/memories/list.tsservers/api/src/routes/memories/list.test.tsservers/api/src/routes/task-runs/list.tsservers/api/src/routes/task-runs/list.test.tsservers/api/src/routes/task-runs/list-messages.tsservers/api/src/routes/task-runs/list-messages.test.tsservers/api/src/routes/usage/get.tsservers/api/src/routes/usage/get.test.tsservers/api/src/routes/usage/get-agent.tsservers/api/src/routes/usage/get-agent.test.tsservers/api/src/routes/agents/list-versions.tsservers/api/src/routes/agents/list-versions.test.tsservers/api/src/routes/agents/list.tsservers/api/src/routes/agents/list.test.tsservers/api/src/routes/agents/list-mcp-attachments.tsservers/api/src/routes/agents/mcp-attachments.test.tsservers/api/src/routes/apikeys/list.tsservers/api/src/routes/apikeys/list.test.tsservers/api/src/routes/providers/list.tsservers/api/src/routes/providers/list.test.tsservers/api/src/routes/mcp-connections/list.tsservers/api/src/routes/mcp-connections/routes.test.tsservers/api/src/routes/prompts/list.tsservers/api/src/routes/prompts/list.test.tsservers/api/src/routes/skills/list.tsservers/api/src/routes/skills/list.test.tsservers/api/src/routes/sandboxes/list.tsservers/api/src/routes/sandboxes/crud.test.tsservers/api/src/routes/tasks/list.tsservers/api/src/routes/tasks/list.test.tspackages/server-core/src/agent-session-service.tspackages/server-core/src/artifact-service.tspackages/server-core/src/memory-service.tspackages/server-core/src/task.tspackages/server-core/src/task-run.ts
Related guides
See the capability and guide links under Used by.
Reference
See the implementation inventory under Source of truth.