v1

latestOpenAPI 3.1.0Proprietary2026-07-2662032.5 KB
FIM

Create a fill-in-the-middle completion

Generate a code completion given a prompt (prefix) and optional suffix. Designed for IDE-style inline completion. Returns a FimCompletion object, or a server-sent events stream of FimCompletionChunk deltas when stream=true. Tool calling and function calling are not supported.

post/v1/fim/completions

Request body

promptstring required

The prompt to complete.

suffixstring

The suffix to complete.

modelstring required

The model to use for the FIM completion.

max_tokensinteger

Maximum number of tokens to generate.

top_pnumber

Float that controls the cumulative probability of the top tokens to consider.

top_kinteger

Limits sampling to the k most likely tokens. Must be -1 (disables the cutoff and considers all tokens) or an integer from 1 to 1000; other values such as 0 are rejected.

frequency_penaltynumber

Number between -2 and 2. Positive values penalize tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

presence_penaltynumber

Number between -2 and 2. Positive values penalize tokens based on whether they have appeared in the text so far, increasing the model's likelihood to talk about new topics.

repetition_penaltynumber

Penalizes tokens that have already appeared in the generated text. Must be greater than 0. Values greater than 1.0 discourage repetition; 1.0 applies no penalty.

stopstring[]

A list of sequences where the API will stop generating further tokens. The returned text will not contain the stop sequences. Defaults to common code-block boundaries.

streamboolean

Whether to stream the response.

Response

Successful response. Returns a JSON object when stream=false, or a server-sent events stream of TextCompletionChunk objects (terminated by data: [DONE]) when stream=true.

idstring required
object'text_completion' required
createdinteger required
modelstring required
warningstring nullable

Example response

{
  "id": "cmpl-7a2b3c4d5e",
  "object": "text_completion",
  "created": 1745798400,
  "model": "mercury-edit-2",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "text": "fibonacci(n - 1) + fibonacci(n - 2)"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 14,
    "total_tokens": 38,
    "reasoning_tokens": 0,
    "cached_input_tokens": 0
  }
}