Skip to main content

GET /api/vote

Retrieve all votes for a specific chat.

Authentication

Requires authenticated session. Returns 401 if not authenticated.

Query parameters

chatId
string
required
The chat ID to retrieve votes for

Request example

GET /api/vote?chatId=550e8400-e29b-41d4-a716-446655440000

Response

Returns array of votes for the chat.
[
  {
    "chatId": "550e8400-e29b-41d4-a716-446655440000",
    "messageId": "660e8400-e29b-41d4-a716-446655440001",
    "isUpvoted": true
  },
  {
    "chatId": "550e8400-e29b-41d4-a716-446655440000",
    "messageId": "770e8400-e29b-41d4-a716-446655440002",
    "isUpvoted": false
  }
]

Vote properties

chatId
string
Chat UUID
messageId
string
Message UUID
isUpvoted
boolean
true for upvote, false for downvote

Error responses

400
Bad Request
Missing chatId parameter
401
Unauthorized
Not authenticated
403
Forbidden
Chat belongs to different user
404
Not Found
Chat does not exist
From app/(chat)/api/vote/route.ts:5-35

PATCH /api/vote

Vote on a message (upvote or downvote).

Authentication

Requires authenticated session. Returns 401 if not authenticated.

Request body

chatId
string
required
The chat ID containing the message
messageId
string
required
The message ID to vote on
type
string
required
Vote type: "up" or "down"

Request examples

{
  "chatId": "550e8400-e29b-41d4-a716-446655440000",
  "messageId": "660e8400-e29b-41d4-a716-446655440001",
  "type": "up"
}

Response

Returns success message.
200 OK
Message voted

Error responses

400
Bad Request
Missing required parameters (chatId, messageId, or type)
401
Unauthorized
Not authenticated
403
Forbidden
Chat belongs to different user
404
Not Found
Chat or vote does not exist
From app/(chat)/api/vote/route.ts:37-75

Vote behavior

When voting on a message for the first time:
  • Creates a new vote record
  • Sets isUpvoted to true (for “up”) or false (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
From lib/db/schema.ts:85-101

Implementation details

From lib/db/queries.ts:282-311, the voting process:
  1. Check if vote already exists for the message
  2. If exists: Update isUpvoted field
  3. If not exists: Insert new vote record
  4. Vote type “up” sets isUpvoted = true
  5. Vote type “down” sets isUpvoted = false
Votes help track user feedback on AI responses and can be used to improve model performance over time.

Build docs developers (and LLMs) love