Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Wikedhart18/nextjs-ai-chatbot/llms.txt

Use this file to discover all available pages before exploring further.

All endpoints require an active session cookie obtained via the authentication flow. Unauthenticated requests receive a 401 Unauthorized response.

POST /api/chat

Send a message and stream the AI response back to the client. If the chat ID does not yet exist in the database, a new chat record is created automatically with a generated title. The response is a AI SDK data stream (text/plain transfer-encoding chunked). The stream includes text deltas, reasoning tokens (when the reasoning model is selected), and tool-call results. Authentication: required (session cookie)

Request body

id
string
required
UUID of the chat conversation. Generate a new UUID on the client when starting a fresh conversation.
messages
Message[]
required
Full conversation history in AI SDK Message format. The last entry must be a user message.
selectedChatModel
string
required
The model identifier to use for this turn. One of:
ValueDescription
chat-model-smallFast, lower-cost model
chat-model-largeHigh-capability model
chat-model-reasoningExtended reasoning model (tools disabled)

Response

A streaming text/plain data stream in the AI SDK wire format. The stream carries:
  • Text deltas — incremental assistant text tokens.
  • Reasoning tokens — present when selectedChatModel is chat-model-reasoning.
  • Tool results — for getWeather, createDocument, updateDocument, and requestSuggestions (disabled for the reasoning model).

Error codes

StatusMeaning
400No user message found in the provided messages array.
401Missing or invalid session.
500Internal error during streaming (the stream body will contain "Oops, an error occured!").

Example

curl
curl -X POST https://your-app.vercel.app/api/chat \
  -H 'Content-Type: application/json' \
  -H 'Cookie: authjs.session-token=<token>' \
  --no-buffer \
  -d '{
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "messages": [
      { "id": "msg_1", "role": "user", "content": "What is the weather in Paris?" }
    ],
    "selectedChatModel": "chat-model-small"
  }'
TypeScript (AI SDK)
import { useChat } from 'ai/react';

const { messages, input, handleInputChange, handleSubmit } = useChat({
  api: '/api/chat',
  body: {
    selectedChatModel: 'chat-model-small',
  },
  id: chatId,
});

DELETE /api/chat

Permanently delete a chat and all of its messages and votes. Authentication: required (session cookie). You can only delete chats that belong to your user account.

Query parameters

id
string
required
UUID of the chat to delete.

Response

Returns 200 Chat deleted as plain text on success.

Error codes

StatusMeaning
401Missing or invalid session, or the chat belongs to a different user.
404No id query parameter was provided.
500Unexpected database error.

Example

curl
curl -X DELETE \
  'https://your-app.vercel.app/api/chat?id=550e8400-e29b-41d4-a716-446655440000' \
  -H 'Cookie: authjs.session-token=<token>'
TypeScript
await fetch(`/api/chat?id=${chatId}`, { method: 'DELETE' });

POST /api/files/upload

Upload an image file to Vercel Blob storage. The returned URL can be passed as an image content part inside a messages array to give the model visual context. Authentication: required (session cookie)

Request body

Multipart form-data with the following field:
file
File
required
The image to upload. Constraints:
  • Maximum size: 5 MB
  • Accepted types: image/jpeg, image/png

Response

Returns the Vercel Blob PutBlobResult object as JSON.

Error codes

StatusMeaning
400No file provided, empty request body, file exceeds 5 MB, or unsupported file type.
401Missing or invalid session.
500Vercel Blob upload failed or request could not be processed.

Example

curl
curl -X POST https://your-app.vercel.app/api/files/upload \
  -H 'Cookie: authjs.session-token=<token>' \
  -F 'file=@/path/to/image.png'
TypeScript
const formData = new FormData();
formData.append('file', file);

const response = await fetch('/api/files/upload', {
  method: 'POST',
  body: formData,
});

const { url } = await response.json();

Build docs developers (and LLMs) love