Search⌘ K
AI Features

API Model for the AI Code Assistant Service

Model the API of the AI code assistant using the decisions from the preceding lesson. Define a versioned base URL and group the endpoints by completion, chat, and assisted edits. Specify the shared JSON entities, the streaming and retry behavior, and the error responses for failed requests.

This lesson models the API of the AI code assistant using the decisions from the preceding lesson. We will define a versioned base URL, group the endpoints by the three paths including completion, chat, and assisted edits, specify the shared JSON entities, and describe how failed requests are reported. The editor client owns the editor state and the recent chat turns, and the service stores only a request record and its final state, so no conversation resource exists.

Base URL and API endpoints

The following host and version prefix are illustrative:

Shell
https://api.codeassistant.example.com/v1

The API groups operations by request path, as the following map shows:

API endpoints of the AI code assistant service

Each request carries a requestID that doubles as the key of its final-state record. Edit jobs add a jobID so the client can poll or cancel after a lost connection. Canceling changes a job's state; it does not delete the job or touch the repository.

Message format for API endpoints

A schema is a promise about what crosses the wire. Here, it protects retries, stale-response handling, and conflict detection between the editor, the API gateway, and the model workers. ...

Javascript (babel-node)
type CodeAssistantService
{
completion_service
{
requestID: string // Client-generated ID that traces the request
filePath: string
fileVersion: string // Editor state the request was made against
language: string
prefix: string // Redacted text before the cursor
suffix: string // Redacted text after the cursor
cursorPosition: object // line and character
relatedContext: array? // Optional open-tab snippets or recent symbols, token-capped
maxSuggestions: unsigned integer
timeoutMs: unsigned integer?
suggestions: array // suggestionID, text, confidence, range
}
chat_service
{
requestID: string
repoID: string
context: object // filePath, fileVersion, language, optional selection
messages: array // Bounded recent turns; role is user or assistant
maxOutputTokens: unsigned integer
status: string // generating, completed, interrupted, or failed
contextMode: string // full or local
references: array // filePath and symbol used by the answer
}
edit_job_service
{
jobID: string
requestID: string
repoID: string
instruction: string
files: array // filePath, fileVersion, optional selection
maxOutputTokens: unsigned integer
status: string // pending, running, completed, failed, or canceled
progress: object? // stage while running
fileDiffs: array // filePath, originalVersion, patch, summary
usage: object?
error: object?
createdAt: timestamp
updatedAt: timestamp
completedAt: timestamp?
}
repo_index_service
{
repoID: string
status: string // indexing, ready, or failed
updatedAt: timestamp
}
}

Request inline completions

Inline completion is the latency-critical path, so the IDE sends only the context around the cursor to POST /v1/completions/inline, with a timeoutMs budget. The service returns one suggestion with a replacement range and echoes fileVersion so the client can discard stale results.

The following request carries the editor state around the cursor: