Skip to main content

Overview

The /api/completion endpoint provides intelligent inline writing assistance for text completions, transformations, grammar fixes, and style adjustments. It’s designed for seamless integration into text editors and input fields, offering personalized suggestions based on user memory.
This endpoint returns Server-Sent Events (SSE) for streaming completions.

Endpoint

Authentication

Requires authentication via cookies or Authorization header. Alternatively, accepts userId in request body for internal calls.
Returns 401 Unauthorized if authentication fails.

Request Body

UIMessage[]
required
Array of messages containing the text to complete or transform. Typically contains a single user message with the input text.
ActionType
required
The type of completion or transformation to perform.
string
Custom instructions to prepend to the system prompt. Used when action is "custom" or when you want to provide additional context.
string
User identifier. Used as fallback if authentication via cookies/headers is not available.

Response

Returns a Server-Sent Events (SSE) stream with JSON payloads:
string
Event type (text, tool-call, tool-result, reasoning, finish).
string
Text chunk or event content. For completions, this contains the transformed/completed text.
string
Unique message or chunk ID.

Available Tools

The completion endpoint has access to memory tools for personalization:

Behavior

The completion endpoint is designed to:
  • Return only the final transformed text (no explanations or preambles)
  • Always search memory first to personalize the output
  • Match the user’s preferred writing style and tone
  • Preserve formatting and capitalization preferences
  • Store corrections and feedback for future improvements

Example Request

Example with Custom Prompt

Example Response Stream

Error Responses

error
Returned when messages parameter is missing or invalid.
error
Returned when authentication fails.

Use Cases

  • Grammar Correction: Fix spelling and grammar errors inline
  • Tone Adjustment: Convert between professional, casual, and friendly tones
  • Email Writing: Transform quick notes into polished emails
  • Text Expansion: Add detail and context to brief text
  • Text Condensing: Shorten verbose text while preserving meaning
  • Code Completion: Complete or format code snippets
  • Translation: Translate and adapt text to different languages and styles
  • Creative Writing: Continue stories or creative content

Best Practices

  • Let the system search memory automatically - it will personalize based on past interactions
  • Use action types for common transformations instead of custom prompts when possible
  • For email writing, the system will automatically include the user’s signature if stored in memory
  • The endpoint learns from corrections, so user feedback improves future completions