GET /api/chat/messages returns a page of messages, oldest first. It is the read path for chat
content.
Paging
Paging is by cursor. Each message carries an opaquecursor, and each page carries a
nextCursor that points at the page before it.
- Open the chat with no parameters. The response is the newest page.
- To load older messages, send
nextCursoras thebeforeparameter. - Repeat until
hasMoreisfalse.
limit is 50 by default and 100 at most.
The cursor is opaque. Do not parse it, and do not build one. Its format can change. Send back only
a value the API gave you.
Catch up after a lost connection
Theafter parameter reads forward instead of backward. Send the cursor of your newest message to
get everything that arrived since. Use it after the realtime stream closes. Read
Realtime updates.
Message fields
What the model sees
The model reads the last 60 messages plus rolling summaries of what came before. This window is independent of your paging: the student can scroll back through the whole conversation, and the window stays at 60.When to call it
Call the endpoint at these four moments:- When the chat screen opens.
- When the application returns to the foreground.
- When the student scrolls to the top of the loaded messages, with
before. - After the realtime stream closes, with
after.
Local state
Every message has a stableid. Merge the server response into the local list by id, and
replace an optimistic local copy when the real message arrives.