Skip to main content
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 opaque cursor, and each page carries a nextCursor that points at the page before it.
  1. Open the chat with no parameters. The response is the newest page.
  2. To load older messages, send nextCursor as the before parameter.
  3. Repeat until hasMore is false.
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

The after 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:
  1. When the chat screen opens.
  2. When the application returns to the foreground.
  3. When the student scrolls to the top of the loaded messages, with before.
  4. After the realtime stream closes, with after.
Do not poll. Read Realtime updates.

Local state

Every message has a stable id. Merge the server response into the local list by id, and replace an optimistic local copy when the real message arrives.