Setup
Step 1: Enable Rewriter
- React / Next.js
- Other Frameworks
Step 2: Subscribe to text selection events
Subscribe to Rewriter events. Supports'textSelected' to receive a TextSelectedEvent whenever a user selects text in a Rewriter-enabled region.
- Params:
action: 'textSelected' - Returns:
Observable<TextSelectedEvent>
- React / Next.js
- Other Frameworks
Step 3: Send a prompt to AI
Send a text-generation prompt to any AI model via Velt’s api. The provider is resolved automatically from the model name prefix (gpt-*/o1-*/o3-*/o4-* → OpenAI, claude-* → Anthropic, gemini-* → Gemini).
- Params:
RewriterAskAiRequest - Returns:
Promise<RewriterAskAiResponse>
- React / Next.js
- Other Frameworks
Step 4: Take action on the returned result
Once you have the AI response, you can either replace the selected text in the DOM or anchor a comment to it. Choose the option that fits your use case, or combine both.- Option A: Replace selected text
- Option B: Add a comment to selected text
Replace the DOM text identified by a
TextSelectedEvent with new text.- Params:
RewriterReplaceTextRequest - Returns:
Promise<RewriterReplaceTextResponse>
- React / Next.js
- Other Frameworks
Complete Example
- React / Next.js
- Other Frameworks

