GET /api/vote
Retrieve all votes for a specific chat.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
The chat ID to retrieve votes for
Request example
Response
Returns array of votes for the chat.Vote properties
Chat UUID
Message UUID
true for upvote, false for downvoteError responses
Missing chatId parameter
Not authenticated
Chat belongs to different user
Chat does not exist
app/(chat)/api/vote/route.ts:5-35
PATCH /api/vote
Vote on a message (upvote or downvote).Authentication
Requires authenticated session. Returns401 if not authenticated.
Request body
The chat ID containing the message
The message ID to vote on
Vote type:
"up" or "down"Request examples
Response
Returns success message.Error responses
Missing required parameters (chatId, messageId, or type)
Not authenticated
Chat belongs to different user
Chat or vote does not exist
app/(chat)/api/vote/route.ts:37-75
Vote behavior
- First vote
- Update vote
When voting on a message for the first time:
- Creates a new vote record
- Sets
isUpvotedtotrue(for “up”) orfalse(for “down”)
Database schema
Votes use a composite primary key(chatId, messageId), ensuring:
- Only one vote per message
- Votes are tied to specific messages in specific chats
- Votes are deleted when the chat is deleted
lib/db/schema.ts:85-101
Implementation details
Fromlib/db/queries.ts:282-311, the voting process:
- Check if vote already exists for the message
- If exists: Update
isUpvotedfield - If not exists: Insert new vote record
- Vote type “up” sets
isUpvoted = true - Vote type “down” sets
isUpvoted = false
Votes help track user feedback on AI responses and can be used to improve model performance over time.