Skip to main content

POST /api/suggest

Generate intelligent inline suggestions based on the current context. This endpoint integrates with the user’s memory system to provide personalized, context-aware completions.

Request Body

context
string
required
The current text context where the suggestion will be inserted. This can be selected text or the text around the cursor.
userId
string
required
Unique identifier for the user. Used to retrieve personalized memories.
instruction
string
Optional instruction to guide the suggestion. For example: “complete this sentence” or “suggest next steps”.
model
string
default:"gpt-4o-mini"
The AI model to use for generation. Supported models include:
  • gpt-4o-mini (default)
  • gpt-4o
  • claude-3-5-sonnet-20241022
  • groq/llama-3.3-70b-versatile
  • cerebras/llama-3.3-70b

Response

The endpoint returns a streaming text response with the AI-generated suggestion.
suggestion
string (streaming)
The generated text suggestion, streamed token-by-token for real-time display.

Memory Integration

The suggest endpoint uses three memory tools to provide personalized suggestions:
  1. searchMemory - Searches relevant memories based on the context
  2. addMemory - Stores new facts learned during the interaction
  3. getAllMemories - Retrieves all user memories for comprehensive context
The system automatically:
  • Searches for relevant personal preferences and past context
  • Incorporates your coding style, preferences, and recent work
  • Stores new insights for future suggestions

Example Request

const response = await fetch('http://localhost:3001/api/suggest', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    context: 'const handleSubmit = async () => {',
    userId: 'user_123',
    instruction: 'Complete this function',
    model: 'gpt-4o-mini'
  })
});

const reader = response.body?.getReader();
const decoder = new TextDecoder();

// Read streaming response
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  
  const chunk = decoder.decode(value);
  console.log(chunk); // Display suggestion as it streams
}

Example Response (Streaming)

  try {
    const formData = new FormData();
    formData.append('data', JSON.stringify(data));
    
    const response = await api.post('/submit', formData);
    if (response.ok) {
      showSuccessToast('Submitted successfully');
    }
  } catch (error) {
    showErrorToast(error.message);
  }
}

Use Cases

Code Completion

Intelligent code completions that match your style and patterns

Writing Assistance

Context-aware text completions for emails and documents

Next-Step Suggestions

Suggest logical next steps based on current context

Personalized Help

Suggestions that incorporate your preferences and history

Keyboard Shortcut

Trigger inline suggestions with Ctrl+Space in the Tabby desktop app. Source: nextjs-backend/src/app/api/suggest/route.ts
  • Completion - General text transformations and completions
  • Chat - Full conversational AI with memory
  • Search Memory - Directly query the memory system

Build docs developers (and LLMs) love