GET /api/history
Retrieve paginated chat history for the authenticated user.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
Number of chats to return (pagination limit)
Chat ID to start after (for forward pagination). Returns chats created after this chat.
Chat ID to end before (for backward pagination). Returns chats created before this chat.
You cannot use both
starting_after and ending_before in the same request.Request examples
Response
Returns paginated chat history.Array of chat objects ordered by creation date (newest first)
Whether more results are available for pagination
Response example
Pagination behavior
The endpoint implements cursor-based pagination:- First request: Omit both cursor parameters to get the first page
- Next page: Use
starting_afterwith the ID of the last chat from current page - Previous page: Use
ending_beforewith the ID of the first chat from current page - hasMore: Indicates if more results exist beyond the current page
Error responses
Both
starting_after and ending_before provided, or referenced chat not foundNot authenticated
app/(chat)/api/history/route.ts:6-34
DELETE /api/history
Delete all chats for the authenticated user.Authentication
Requires authenticated session. Returns401 if not authenticated.
Request example
Response
Returns count of deleted chats.Number of chats deleted
Error responses
Not authenticated
Cascade behavior
Deleting all chats also removes:- All messages in all user’s chats
- All votes on messages
- All stream records
app/(chat)/api/history/route.ts:36-46
Implementation details
Fromlib/db/queries.ts:125-154, the deletion process:
- Queries all chat IDs for the user
- Deletes all votes for those chats
- Deletes all messages for those chats
- Deletes all stream records for those chats
- Deletes all chat records
- Returns count of deleted chats