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. You can only access and modify documents that belong to your user account.

The Document type

Documents are versioned artifacts created by the AI during a conversation. Multiple versions of the same logical document share the same id; each version is distinguished by its createdAt timestamp.
id
string
UUID shared by all versions of this document.
createdAt
string
ISO 8601 timestamp of when this version was created. Together with id this forms the primary key.
title
string
Human-readable title of the document.
content
string | null
Full text or code content of this document version.
kind
string
Artifact type. One of "text", "code", "image", "sheet".
userId
string
UUID of the user who owns the document.

GET /api/document

Fetch all versions of a document in ascending creation order. Authentication: required (session cookie)

Query parameters

id
string
required
UUID of the document to retrieve.

Response

Returns a JSON array of Document objects ordered by createdAt ascending. Each element represents one saved version.
Example response
[
  {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "createdAt": "2024-01-15T10:30:00.000Z",
    "title": "Project proposal",
    "content": "# Project Proposal\n\nThis document outlines...",
    "kind": "text",
    "userId": "550e8400-e29b-41d4-a716-446655440000"
  },
  {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "createdAt": "2024-01-15T11:00:00.000Z",
    "title": "Project proposal",
    "content": "# Project Proposal (revised)\n\nThis document outlines...",
    "kind": "text",
    "userId": "550e8400-e29b-41d4-a716-446655440000"
  }
]

Error codes

StatusMeaning
400id query parameter is missing.
401Missing or invalid session, or the document belongs to a different user.
404No document found with the given ID.

Example

curl
curl 'https://your-app.vercel.app/api/document?id=a1b2c3d4-e5f6-7890-abcd-ef1234567890' \
  -H 'Cookie: authjs.session-token=<token>'
TypeScript
const response = await fetch(`/api/document?id=${documentId}`);
const versions = await response.json(); // Document[]

POST /api/document

Save a new version of a document. Each call appends a new version record; prior versions are preserved. Authentication: required (session cookie)

Query parameters

id
string
required
UUID of the document. Use an existing document UUID to add a new version, or generate a new UUID to create a fresh document.

Request body

title
string
required
Human-readable title for this version.
content
string
required
Full content of the document version.
kind
string
required
Artifact type. One of "text", "code", "image", "sheet".

Response

Returns the newly created Document object as JSON with status 200.

Error codes

StatusMeaning
400id query parameter is missing.
401Missing or invalid session.

Example

curl
curl -X POST \
  'https://your-app.vercel.app/api/document?id=a1b2c3d4-e5f6-7890-abcd-ef1234567890' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: authjs.session-token=<token>' \
  -d '{
    "title": "Project proposal",
    "content": "# Project Proposal\n\nContent here...",
    "kind": "text"
  }'
TypeScript
const response = await fetch(`/api/document?id=${documentId}`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ title, content, kind }),
});
const document = await response.json();

PATCH /api/document

Delete all document versions created after a given timestamp. Use this to revert a document to an earlier version.
This operation is irreversible. All versions with a createdAt strictly greater than timestamp are permanently deleted, along with any suggestions attached to those versions.
Authentication: required (session cookie). You can only modify documents you own.

Query parameters

id
string
required
UUID of the document to truncate.

Request body

timestamp
string
required
ISO 8601 datetime string. All document versions (and associated suggestions) with a createdAt strictly after this value are deleted.

Response

Returns 200 Deleted as plain text on success.

Error codes

StatusMeaning
400id query parameter is missing.
401Missing or invalid session, or the document belongs to a different user.

Example

curl
curl -X PATCH \
  'https://your-app.vercel.app/api/document?id=a1b2c3d4-e5f6-7890-abcd-ef1234567890' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: authjs.session-token=<token>' \
  -d '{ "timestamp": "2024-01-15T10:45:00.000Z" }'
TypeScript
await fetch(`/api/document?id=${documentId}`, {
  method: 'PATCH',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ timestamp: revertToDate.toISOString() }),
});

Build docs developers (and LLMs) love