Overview
The AI Suggestions API provides intelligent code completion and editing capabilities. Get real-time code suggestions as you type or quickly edit selected code with natural language instructions.Code Suggestion
Get AI-powered code completion at cursor position
Request Body
Name of the file being edited (used for context)
The full code content of the file
The current line where the cursor is located
Line number of the cursor (1-based)
Text before cursor position on the current line
Text after cursor position on the current line
Previous lines for context (optional)
Next lines for context (optional)
Response
The suggested code to insert at cursor position, or empty string if no suggestion
Example Request
cURL
JavaScript
Example Response
Success
No Suggestion
Error Codes
400- Missing required field (code is required)403- Unauthorized500- Failed to generate suggestion
Suggestion Logic
The AI follows these rules:- Check next lines: If code already exists after cursor, return empty string
- Check completion: If line ends with complete statement (
;,},)), return empty string - Generate suggestion: Only suggest if incomplete and no code exists ahead
Suggestions are designed to be non-intrusive. They only appear when the AI is confident the code needs completion and won’t duplicate existing code.
Quick Edit
Edit selected code using natural language instruction (Cmd+K functionality)
Request Body
The code that is currently selected for editing
Natural language instruction describing the desired changes
The full file content for context (optional but recommended)
Response
The edited version of the selected code (or original if instruction unclear)
Example Request
cURL
JavaScript
Example Response
Success
Error Codes
400- Missing selected code or instruction400- Unauthorized (note: returns 400, not 403)500- Failed to generate edit
Documentation Integration
Quick edit can automatically fetch and use documentation from URLs in the instruction:Example with URL
- Extract URLs from the instruction (regex:
https?://[^\s)>\]]+) - Scrape documentation using Firecrawl (if configured)
- Include scraped content in the prompt
- Generate code following the documentation
URL scraping requires
FIRECRAWL_API_KEY environment variable. Without it, URLs in instructions are ignored.AI Configuration
Temperature and Tokens
Both endpoints use these AI parameters:- Temperature:
0.7(balanced creativity) - Suggestion max tokens:
500 - Quick edit max tokens:
2000
Provider Fallback
Both endpoints use thegenerateWithFallback function:
- Primary: Moonshot AI Kimi K2.5 via OpenRouter (via
OPENROUTER_API_KEY) - Fallback: Cerebras GLM-4.7 (via
CEREBRAS_API_KEY)
Integration Examples
CodeMirror Extension
CodeMirror Extension
Quick Edit Keybinding
Quick Edit Integration
Best Practices
Debounce Suggestion Requests
Debounce Suggestion Requests
Avoid sending a request on every keystroke. Use debouncing (300-500ms) to reduce API calls.
Provide Context
Provide Context
Always send
previousLines and nextLines for better suggestions. More context = better results.Handle Empty Responses
Handle Empty Responses
Empty suggestions are normal and expected. Don’t show any UI when
suggestion === "".Cache Recent Suggestions
Cache Recent Suggestions
Cache suggestions for identical cursor positions to avoid redundant API calls.
Show Visual Feedback
Show Visual Feedback
For quick edit, show a loading indicator while processing. The operation can take 1-3 seconds.
Rate Limiting
Suggestions and quick edits use your configured AI provider’s rate limits:- OpenRouter (Kimi K2.5): Depends on your OpenRouter plan
- Cerebras (GLM-4.7): 30 requests/min (free tier)
Next Steps
Messages API
Build conversational AI features
Projects API
Create and manage projects