POST /api/chat
Create a new chat message and stream AI responses. This endpoint handles both new messages and tool approval flows.Authentication
Requires authenticated session. Returns401 if not authenticated.
Request body
The chat ID (UUID format). Used to identify the conversation.
A new user message. Required when sending a new message (not in tool approval flow).
All conversation messages. Used in tool approval flows when continuing from a specific state.
The AI model to use for generating responses. Must be from the allowed models list.
Chat visibility:
"public" or "private"Request example
Response
Returns a streaming response with Server-Sent Events (SSE) containing:A stream of UI messages including text deltas, tool calls, and data events
Response events
- Text delta
- Chat title
- Tool call
Error responses
Invalid request body or unsupported model
Not authenticated or bot detected
Chat belongs to different user
Exceeded daily message limit
Rate limiting
The endpoint enforces:- IP-based rate limiting
- Per-user daily message limits based on user type
- Free users: limited messages per day
- Premium users: higher message limits
Available tools
When using non-reasoning models, the AI can call these tools:- getWeather - Fetch weather information
- createDocument - Create new documents (text, code, image, sheet)
- updateDocument - Update existing documents
- requestSuggestions - Request document editing suggestions
Reasoning models (models ending in
-thinking or containing reasoning) do not have access to tools.Implementation details
Fromapp/(chat)/api/chat/route.ts:54-289:
- Messages are saved to database before streaming begins
- Chat title is auto-generated for new conversations
- Streaming supports resumable streams via Redis (when configured)
- Maximum duration: 60 seconds
- Stop condition: 5 tool execution steps
DELETE /api/chat
Delete a chat conversation and all associated data.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
The chat ID to delete (UUID format)
Request example
Response
The deleted chat object
Error responses
Missing chat ID parameter
Not authenticated
Chat belongs to different user
Cascade behavior
Deleting a chat also removes:- All messages in the chat
- All votes on messages
- All stream records
app/(chat)/api/chat/route.ts:291-314
GET /api/chat/[id]/stream
Health check endpoint for chat streaming. Always returns204 No Content.
From app/(chat)/api/chat/[id]/stream/route.ts:1-4