Endpoint
Authentication
Requires a valid Clerk session token. See Authentication for details.Request Body
The code block to edit. This is the text currently selected in the editor.
Natural language instruction describing the desired changes. Can include URLs for documentation reference.
The complete file content for additional context. Optional but recommended for better results.
Response
The modified version of the selected code based on the instruction. Maintains the same indentation level as the original.
Request Example
Response Example
Documentation Fetching
The endpoint automatically detects URLs in the instruction and fetches their documentation content to provide additional context.URL Detection
URLs are detected using the regex pattern:/https?:\/\/[^\s)>\]]+/g
Example with URL
- Extract the URL from the instruction
- Use Firecrawl to scrape the documentation in Markdown format
- Include the scraped content in the AI prompt for better context
- Generate code that follows the referenced documentation
Supported URL Formats
- HTTP and HTTPS URLs
- Documentation sites
- GitHub repositories
- API references
- Blog posts and tutorials
AI Model
This endpoint uses Claude 3.7 Sonnet (claude-3-7-sonnet-20250219) with structured output to ensure the response contains only the edited code.
Edit Guidelines
The AI follows these principles:Preserve Indentation
Preserve Indentation
The edited code maintains the same indentation level as the original selected code.
Code Only
Code Only
Returns only the edited code without explanations or comments (unless specifically requested in the instruction).
Context Awareness
Context Awareness
Uses the full code context to ensure edits are compatible with the rest of the file.
Instruction Clarity
Instruction Clarity
If the instruction is unclear or cannot be applied, returns the original code unchanged.
Use Cases
Refactoring
“Convert this to use async/await”
Error Handling
“Add try-catch blocks”
Documentation
“Add JSDoc comments”
Type Safety
“Add TypeScript types”
Optimization
“Optimize for performance”
Best Practices
“Follow React best practices”
Error Responses
Description of the error that occurred.
Common Errors
| Status Code | Error | Description |
|---|---|---|
| 400 | Selected code is required | The selectedCode parameter is missing or empty |
| 400 | Instruction is required | The instruction parameter is missing or empty |
| 400 | Unauthorized | Missing or invalid authentication token |
| 500 | Failed to generate edit | AI model error, documentation fetch failure, or internal server issue |
Performance Notes
- Average response time: 1-3 seconds without URL fetching
- With URL fetching: 3-8 seconds depending on documentation size
- Multiple URLs are fetched in parallel
- Failed URL fetches are silently ignored (edit continues without that documentation)
- Response time increases with larger code selections and context
Best Practices
- Provide Full Context: Include
fullCodefor better awareness of imports and dependencies - Clear Instructions: Be specific about the desired changes
- Reference Documentation: Include URLs when following specific patterns or frameworks
- Reasonable Selections: Select complete functions or logical blocks for best results
- Verify Output: Always review the edited code before applying