Tree BG 1
Tree
Tree
TreeLeaves
TreeLeaves
Cat IdleGrassGrassRockRock

Fim Endpoints

Fill-in-the-middle API.

Fim Completion

POST /v1/fim/completions

FIM completion.

200 (application/json)

200 (text/event-stream)

Successful Response

created
*integer
id
*string
model
*string
object
*string
usage
*UsageInfo

Playground

Test the endpoints live

import { Mistral } from "@mistralai/mistralai";

const mistral = new Mistral({
  apiKey: "MISTRAL_API_KEY",
});

async function run() {
  const result = await mistral.fim.complete({
    model: "codestral-2405",
    prompt: "def",
    suffix: "return a+b",
  });

  console.log(result);
}

run();
from mistralai import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.fim.complete(model="codestral-2405", prompt="def", top_p=1, stream=False, suffix="return a+b")

    # Handle response
    print(res)

curl https://api.mistral.ai/v1/fim/completions \
 -X POST \
 -H 'Authorization: Bearer YOUR_APIKEY_HERE' \
 -d '{
  "prompt": "def"
}'

200 (application/json)

200 (text/event-stream)

{
  "id": "447e3e0d457e42e98248b5d2ef52a2a3",
  "object": "chat.completion",
  "model": "codestral-2508",
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 91,
    "total_tokens": 99
  },
  "created": 1759496862,
  "choices": [
    {
      "index": 0,
      "message": {
        "content": "add_numbers(a: int, b: int) -> int:\n    \"\"\"\n    You are given two integers `a` and `b`. Your task is to write a function that\n    returns the sum of these two integers. The function should be implemented in a\n    way that it can handle very large integers (up to 10^18). As a reminder, your\n    code has to be in python\n    \"\"\"\n",
        "tool_calls": null,
        "prefix": false,
        "role": "assistant"
      },
      "finish_reason": "stop"
    }
  ]
}