Search⌘ K
AI Features

AI Code Assistant API Design Decisions

Learn how an editor event moves through context assembly, safety checks, model routing, and response delivery for completion, chat, and assisted edits. Evaluate the choices for request paths, stale-response handling, cancellation, retries, and sensitivity-based routing. Connect each decision to its effect on latency, privacy, and cost.

An AI code assistant receives events from an editor, assembles context from the open file and the repository, generates a suggestion, an answer, or a proposed change, and returns it before the editor state moves on. We will first examine the service's high-level design and trace the workflows for completion, chat, and assisted edits. We will then use those workflows to decide how the API handles request paths, stale responses, cancellation, retries, privacy, and model usage.

Design overview

A request starts as an editor event: a typing pause, a chat question, or an edit request. The service checks whether the request may proceed, prepares the model input from the editor state and relevant repository context, generates output, and returns it. The product has three request paths: completion, chat, and assisted edits. They share one gateway but fall into two latency classes: a fast typing path and a deliberate path for chat and edits.

These responsibilities are logical, not separate deployable services. See how the fast and deliberate paths split below:

Code assistant high-level architecture
Code assistant high-level architecture

Here is the overview of what each component is responsible in the pipeline:

Component

Responsibility

IDE client

Captures editor events and chat questions, masks secrets, and sends the file version with each request.

API gateway

Authenticates the caller, applies tenant policy, and enforces request and token limits.

Context preprocessor

Selects editor and repository context within token and privacy limits, reading only repositories the caller may access.

Repository index

Returns definitions, references, tests, and nearby symbols, and reports readiness.

Safety and redaction

Redacts secrets and personal data before inference.

Model router

Chooses a model tier by task type, latency budget, and repository sensitivity.

Inference cluster

Generates completions, answers, and patches from the assembled context.

Response check

Validates syntax, citations, and redaction before the response is delivered.

Edit job service

Runs each edit through the generation pipeline and tracks its state and result.

Telemetry pipeline

Records timings and failures after redaction.

Workflow

We will follow the actions defined in the requirements: completing code while the developer types, asking about code, requesting an edit, and stopping or discarding work. Each action exposes a decision about the API contract. A request is correct only if its output matches the editor state the developer saw when the request was issued, so every path carries a file version.

Complete code while typing

Inline completion is the fastest path, so small design mistakes show up immediately as visible lag. The client waits for a short typing pause, illustratively 150 to 300 ms, before ...