Endpoint
Authentication
Requires a valid Clerk session token. See Authentication for details.Request Body
The name of the file being edited (e.g.,
index.ts, App.tsx).The complete code content of the file.
The current line where the cursor is positioned.
The line number where the cursor is positioned (1-indexed).
The text on the current line before the cursor position.
The text on the current line after the cursor position.
Lines of code appearing before the current line. Can be empty string.
Lines of code appearing after the current line. Can be empty string.
Response
The code to insert at the cursor position. Returns an empty string if no completion is needed or if the code is already complete.
Request Example
Response Example
AI Model
This endpoint uses Claude 3.7 Sonnet (claude-3-7-sonnet-20250219) with structured output to ensure consistent suggestion formatting.
Suggestion Logic
The AI follows a specific decision tree:- Check Next Lines: If
nextLinescontains code that continues from the cursor, returns empty string (code already exists) - Check Completeness: If
textBeforeCursorends with a complete statement (;,},)), returns empty string - Generate Suggestion: Only if the above conditions don’t apply, generates a contextual completion
When Suggestions Are Empty
The endpoint returns an emptysuggestion when:
- The code is already written in the following lines
- The current statement is already complete
- No meaningful completion can be suggested
Context Usage
The AI analyzes multiple context layers:- File Context: Full code content and file name
- Local Context: Current line, previous lines, and next lines
- Cursor Context: Text immediately before and after cursor
- Structural Context: Line numbers for precise positioning
- Syntactically correct
- Contextually appropriate
- Consistent with existing code style
- Non-redundant with existing code
Error Responses
Description of the error that occurred.
Common Errors
| Status Code | Error | Description |
|---|---|---|
| 400 | Code is required | The code parameter is missing or empty |
| 403 | Unauthorized | Missing or invalid authentication token |
| 500 | Failed to generate suggestion | AI model error or internal server issue |
Performance Notes
- Average response time: 500-2000ms depending on code complexity
- Suggestions are generated synchronously
- Consider implementing client-side debouncing for real-time suggestions
- Cache suggestions when cursor position hasn’t changed