Skip to Content
Konduit docs

Text and code completions

Fill-in-the-middle for code editors and OpenAI's legacy completions — which models serve them, and what one costs.

Two endpoints complete a prompt rather than a conversation:

EndpointWhat it isAnswers with
POST /v1/fim/completionsMistral's fill-in-the-middle: the code before the cursor in prompt, the code after it in suffixa chat.completion; the text to insert is choices[0].message.content
POST /v1/completionsOpenAI's legacy completions: continue prompta text_completion; the text is choices[0].text

Code autocomplete is what both are for. A client that speaks Mistral's FIM API sends prompt and suffix to the first. A client that writes the model's own fill-in-the-middle template into prompt itself — the custom-template mode several editor plugins have — sends that to the second.

curl https://api.konduit.eu/v1/fim/completions \
  -H "Authorization: Bearer $KONDUIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "codestral-2508",
    "prompt": "def add(a, b):\n    ",
    "suffix": "\n\nprint(add(1, 2))",
    "max_tokens": 64
  }'

The response is the provider's own, relayed unchanged, and the Konduit-Provider and Konduit-Deployment headers say who served it, as on a chat completion.

Which models

Not every chat model, and not every deployment of one. Whether an operator serves these routes depends on how it serves the weights, so konduit probes each deployment and lists the answer in deployment.endpoints of GET /v1/models:

curl https://api.konduit.eu/v1/models -H "Authorization: Bearer $KONDUIT_API_KEY" \
  | jq -r '.data[] | select(.deployment.endpoints | index("/v1/fim/completions")) | .id'

model resolves as it does on a chat completion — a model, a model at a provider, or one deployment id — and the provider sovereignty policy applies the same way; see Routing and sovereignty. Only the deployments that list the route are candidates, so a fallback never lands on one that does not. A model none of whose deployments list it is refused with 400 and model_does_not_support_endpoint before anything is reserved or any provider is asked.

What konduit forwards

Your body goes to the provider as you sent it, with three things changed: model becomes the provider's own name for the deployment, the provider policy is removed, and on a stream konduit sets stream_options.include_usage to true. konduit checks only that there is a model and that prompt is one string. The legacy API's array forms — several prompts, or token ids — are refused with 400 invalid_request: the provider would answer each element with a completion of its own, on credit reserved for one. Send one request per prompt. suffix, stop, temperature and the rest are forwarded untouched and are the provider's to judge, so a refusal comes back as upstream_invalid_request with the provider's own message:

  • The providers behind /v1/completions refuse suffix. Send fill-in-the-middle with a suffix to /v1/fim/completions, or write it into prompt yourself.
  • Mistral refuses a field it does not know on /v1/fim/completions with a 422. Send only the fields its FIM API documents.

Streaming and usage

Both routes stream with "stream": true, and both bill only from the provider's own counts, which konduit always asks for. Whether you receive them is up to you, as on a chat completion — see Streaming:

  • On /v1/completions the counts arrive on a final chunk of their own with empty choices. You receive it only if you sent "stream_options": {"include_usage": true}.
  • On /v1/fim/completions Mistral puts the counts on the chunk that carries the last tokens. If you did not ask for usage you still receive that chunk, with "usage": null.

What it costs

A completion is billed like a chat completion: the provider's usage, at the deployment's input and output prices. Send max_tokens. konduit reserves credit for the longest completion the request could produce before it runs. Without max_tokens that is the deployment's max_output_tokens from GET /v1/models, or its whole context window when it publishes none — codestral-2508 publishes none, so a FIM request without max_tokens reserves 256 000 tokens — while the provider's own default may be as short as 16 tokens. The difference goes back the moment the request is charged, but until then it is credit you cannot spend, and an editor with several requests in flight can meet a 402 on a balance that easily covers the real completions; see Rate limits.

n (and best_of on /v1/completions) multiplies the reservation, because each choice is a completion the provider bills. The installation's per-request reservation limit clamps only a request for one choice: one for several whose whole reservation would exceed it is refused with 400 invalid_request before anything is reserved — without max_tokens, too, when the deployment's ceiling is its whole context window. Set or lower max_tokens, or lower n or best_of.

Autocomplete without surprises

An editor that asks on every keystroke sends many small requests, and each one counts against the same requests-per-minute and tokens-per-minute limits as a chat completion; see Rate limits. Debounce — wait until the typing pauses — rather than sending one request per key.

Cancelling a request does not cancel its charge. The provider bills konduit for a completion it has started, so konduit keeps reading its answer after you have gone, for a bounded time, and bills you from the provider's usage. A request you abandon for the next keystroke is paid for.

Scope

A key limited with scopes needs completions:write for both endpoints; chat:write does not include them, and completions:write does not include chat. A key with no scopes can call everything; see Authentication.

On this page