Sessions
session.history()
Read paged history for the current Session
session.history()
Example
const history = await session.history({
limit: 50,
});
console.log(history.items);What it returns
It returns a paged history object for the current session.
Common fields include:
history.sessionhistory.viewhistory.itemshistory.totalhistory.next_cursorhistory.has_morehistory.archive_idhistory.previous_archive_id
The default view is message.
session.history() reads the current messages.jsonl layer by default. Compact summaries remain part of the model context, but they are not returned as user-visible items. If the current layer has an older compacted layer, the page includes previous_archive_id:
const current = await session.history({
limit: 50,
});
if (current.previous_archive_id) {
const previous = await session.history({
archive_id: current.previous_archive_id,
limit: 50,
});
console.log(previous.items);
}next_cursor / has_more only paginate the current layer. previous_archive_id lets you jump to the next older compact archive layer.
If you want a flattened UI-oriented event stream, pass:
const history = await session.history({
view: "timeline",
limit: 100,
});Good use cases
- replaying a conversation in UI
- loading only the latest page in a transcript or sidebar
- debugging the current context
- exporting session history
If you need to understand why a particular answer came out the way it did, message history is usually one of the first places worth inspecting.