GET /api/document
Retrieve all versions of a document by ID.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
The document ID to retrieve
Request example
Response
Returns an array of document versions ordered by creation date.Array of document versions
Document properties
Document UUID
Document title
Document content (can be null)
Document type:
"text", "code", "image", or "sheet"Owner user ID
ISO 8601 timestamp
Error responses
Missing document ID parameter
Not authenticated
Document belongs to different user
Document does not exist
app/(chat)/api/document/route.ts:10-40
POST /api/document
Create a new version of a document or save a new document.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
The document ID (UUID format)
Request body
Document title
Document content
Document type:
"text", "code", "image", or "sheet"Request example
URL example
Response
Returns the created document.Error responses
Missing required parameters
Not authenticated
Attempting to update document owned by different user
Document versioning
Documents use composite primary key(id, createdAt), allowing multiple versions:
- Each save creates a new version with same ID but different timestamp
- Retrieve all versions with GET endpoint
- Delete versions after specific timestamp with DELETE endpoint
app/(chat)/api/document/route.ts:42-85
DELETE /api/document
Delete document versions created after a specific timestamp.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
The document ID
ISO 8601 timestamp. Versions created after this time will be deleted.
Request example
Response
Returns array of deleted document versions.Error responses
Missing required parameters (id or timestamp)
Not authenticated
Document belongs to different user
Cascade behavior
Deleting documents also removes associated suggestions created after the timestamp. Fromapp/(chat)/api/document/route.ts:87-126
Use this endpoint to implement “undo” functionality by deleting versions created after a user’s last accepted edit.