Skip to content
anythingai.space
Backend for AIbeginner10 min · 10 steps

Pagination

Return large result sets in bounded pages, by offset or by cursor, in your own APIs and when your tools consume other people's.

SELECT * …one giant JSONAND THE AGENT TOOL…reads page 1 onlywrong answerfollows next forevernever endsreturns every pagecontext overflowChat UIfrozenAssistant APIGET /tickets40,000 rowsmessages2,000,000 rows
heavy workrequestresponsedata
metrics are illustrative
1 / 10
ProblemStep 1 of 10

"Give me everything" doesn't scale

GET /tickets returns 40,000 rows: a slow query, a huge response, and a browser that freezes. On the other side, a naive tool that calls ServiceNow reads only the first page and tells the model "you have 50 tickets", or follows next links forever.

Agents add a twist: every page a tool returns lands in the model's context window.

Lesson 18 of 20 in Backend for AI