---
title: "Create a fill-in-the-middle completion"
method: POST
path: "/v1/fim/completions"
tags: ["FIM"]
---

# Create a fill-in-the-middle completion

`POST /v1/fim/completions`

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.

## Request body

- FIMCompletionRequest
  - `prompt` string, required — The prompt to complete.
  - `suffix` string — The suffix to complete.
  - `model` string, required — The model to use for the FIM completion.
  - `max_tokens` integer — Maximum number of tokens to generate.
  - `top_p` number — Float that controls the cumulative probability of the top tokens to consider.
  - `top_k` integer — 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_penalty` number — 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_penalty` number — 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_penalty` number — 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.
  - `stop` string[] — 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.
  - `stream` boolean — Whether to stream the response.
  - `stream_options` StreamOptions — Options for controlling streaming behavior. Only used when `stream=true`.
    - `include_usage` boolean — If true, an additional chunk is streamed before the `data: [DONE]` message containing the token usage statistics for the entire request. Inside that chunk, `choices` is an empty array and the `usage` field is populated.

## Response `200`

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`.

- FIMCompletionResponse
  - `id` string, required
  - `object` 'text_completion', required
  - `created` integer, required
  - `model` string, required
  - `choices` TextCompletionChoice[], required
    - `index` integer, required
    - `text` string, required
    - `finish_reason` 'stop' | 'length' | 'content_filter' | 'null', nullable, required — The reason the model stopped generating tokens.
  - `usage` FIMUsage, required — Usage for FIM completions.
    - `prompt_tokens` integer, required
    - `reasoning_tokens` integer, required
    - `completion_tokens` integer, required
    - `total_tokens` integer, required
    - `cached_input_tokens` integer, required
  - `warning` string, nullable

## Other responses

- `400` — Bad Request — invalid parameters.
- `401` — Unauthorized — missing or invalid API key.
- `402` — Payment Required — billing inactive or quota exceeded.
- `404` — Not Found — model not available for this account.
- `429` — Too Many Requests — rate limit exceeded.
- `500` — Internal Server Error.

---

[API](https://skmtc.dev/inceptionlabs/apis/inception-api.md) · [All operations](https://skmtc.dev/inceptionlabs/apis/inception-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/inceptionlabs/inception-api/revisions/f42ebbad1e95/schema)
