GET /api/suggestions
Retrieve all suggestions for a specific document.Authentication
Requires authenticated session. Returns401 if not authenticated.
Query parameters
The document ID to retrieve suggestions for
Request example
Response
Returns array of suggestions for the document.Suggestion properties
Suggestion UUID
Associated document UUID
Timestamp of the document version this suggestion applies to
The original text being modified
The suggested replacement text
Optional description of the suggestion (can be null)
Whether the suggestion has been accepted or rejected
User ID who owns the document
ISO 8601 timestamp when suggestion was created
Response when no suggestions
If no suggestions exist for the document, returns empty array:Error responses
Missing documentId parameter
Not authenticated
Document belongs to different user (suggestions inherit document ownership)
app/(chat)/api/suggestions/route.ts:5-37
How suggestions work
- Generation
- Application
- Versioning
Suggestions are generated by the AI using the
requestSuggestions tool during chat:- User asks AI to suggest improvements to a document
- AI analyzes document content
- AI calls
requestSuggestionstool with suggested edits - Suggestions are saved to database
- UI displays suggestions as inline edits
Database schema
Fromlib/db/schema.ts:128-150, suggestions have:
- Primary key:
id - Foreign key:
(documentId, documentCreatedAt)referencesdocument(id, createdAt) - User ownership via
userId - Resolution tracking via
isResolved
Database queries
Fromlib/db/queries.ts:417-448:
Suggestions provide a collaborative editing experience where the AI can propose specific changes that users can review and accept.
Use cases
- Code refactoring suggestions
- Grammar and style improvements for text documents
- Data formatting suggestions for spreadsheets
- Accessibility improvements
- Performance optimizations