mistralM

Docs

Fim

Fill-in-the-middle API.

POST /v1/fim/completions

Fim Completion

FIM completion.

Request Example

{
  "prompt": "def"
}

Request Body

max_tokens
integer | null

The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length.

metadata
map<any> | null
min_tokens
integer | null

The minimum number of tokens to generate in the completion.

model
string

ID of the model with FIM to use.

Example:

codestral-latest

Default Value: "codestral-2404"

prompt
string* required

The text/code to complete.

Example:

def
prompt_cache_key
string | null
random_seed
integer | null

The seed to use for random sampling. If set, different calls will generate deterministic results.

stop
string | array<string> | null

Stop generation if this token is detected. Or if one of these tokens is detected when providing an array

stream
boolean

Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.

Default Value: false

suffix
string | null

Optional text/code that adds more context for the model. When given a prompt and a suffix the model will fill what is between them. When suffix is not provided, the model will simply execute completion starting with prompt.

Example:

return a+b
temperature
number | null

What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both. The default value varies depending on the model you are targeting. Call the /models endpoint to retrieve the appropriate value.

top_p
number | null

Nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.

Responses

Successful Response

choices
array<ChatCompletionChoice>* required
ChatCompletionChoice
finish_reason
"stop" | "length" | "model_length" | "error" | "tool_calls"* required

Example:

stop
index
integer* required

Example:

0
ChatCompletionResponseChoiceLogprobs
ChatCompletionResponseTokenLogprobsTopK
bytes
array<integer>* required
logprob
number* required
token
string* required
token_id
integer* required
top_logprobs
array<ChatCompletionResponseTokenLogprobs> | null
ChatCompletionResponseTokenLogprobs
bytes
array<integer>* required
logprob
number* required
token
string* required
token_id
integer* required
AssistantMessage
TextChunk
text
string* required
type
string

Default Value: "text"

ImageURLChunk

{"type":"image_url","image_url":"data:image/png;base64,iVBORw0"}

image_url
ImageURL | string* required
ImageURL
detail
"low" | "auto" | "high"
url
string* required
type
string

Default Value: "image_url"

DocumentURLChunk
document_name
string | null

The filename of the document

document_url
string* required
type
string

Default Value: "document_url"

ReferenceChunk
reference_ids
array<integer | string>* required
type
string

Default Value: "reference"

FileChunk
file_id
string* required
type
string

Default Value: "file"

ThinkChunk
closed
boolean

Whether the thinking chunk is closed or not. Currently only used for prefixing.

Default Value: true

signature
string | null

Signature to replay some reasoning blocks across turns.

thinking
array<TextChunk | ToolReferenceChunk | ReferenceChunk>* required
TextChunk
text
string* required
type
string

Default Value: "text"

ToolReferenceChunk
description
string | null
favicon
string | null
title
string* required
tool
"web_search" | "web_search_premium" | "code_interpreter" | "image_generation" | "document_library" | "mistral_mcp" | string* required
type
string

Default Value: "tool_reference"

url
string | null
ReferenceChunk
reference_ids
array<integer | string>* required
type
string

Default Value: "reference"

type
string

Default Value: "thinking"

AudioChunk
input_audio
string* required
type
string

Default Value: "input_audio"

ResourceChunk
type
string

Default Value: "resource"

uri
string* required
ResourceLinkChunk
metadata
map<string | integer | number | boolean> | null
type
string

Default Value: "resource_link"

uri
string* required
prefix
boolean

Set this to true when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message.

Default Value: false

role
string

Default Value: "assistant"

tool_calls
array<ToolCall> | null
ToolCall
function
FunctionCall* required
FunctionCall
arguments
map<any> | string* required
name
string* required
id
string
index
integer

Default Value: 0

type
"function"
messages
array<DeltaMessage>
DeltaMessage
TextChunk
text
string* required
type
string

Default Value: "text"

ImageURLChunk

{"type":"image_url","image_url":"data:image/png;base64,iVBORw0"}

image_url
ImageURL | string* required
ImageURL
detail
"low" | "auto" | "high"
url
string* required
type
string

Default Value: "image_url"

DocumentURLChunk
document_name
string | null

The filename of the document

document_url
string* required
type
string

Default Value: "document_url"

ReferenceChunk
reference_ids
array<integer | string>* required
type
string

Default Value: "reference"

FileChunk
file_id
string* required
type
string

Default Value: "file"

ThinkChunk
closed
boolean

Whether the thinking chunk is closed or not. Currently only used for prefixing.

Default Value: true

signature
string | null

Signature to replay some reasoning blocks across turns.

thinking
array<TextChunk | ToolReferenceChunk | ReferenceChunk>* required
TextChunk
text
string* required
type
string

Default Value: "text"

ToolReferenceChunk
description
string | null
favicon
string | null
title
string* required
tool
"web_search" | "web_search_premium" | "code_interpreter" | "image_generation" | "document_library" | "mistral_mcp" | string* required
type
string

Default Value: "tool_reference"

url
string | null
ReferenceChunk
reference_ids
array<integer | string>* required
type
string

Default Value: "reference"

type
string

Default Value: "thinking"

AudioChunk
input_audio
string* required
type
string

Default Value: "input_audio"

ResourceChunk
type
string

Default Value: "resource"

uri
string* required
ResourceLinkChunk
metadata
map<string | integer | number | boolean> | null
type
string

Default Value: "resource_link"

uri
string* required
index
integer | null

If the completion returns multiple messages, this is to specify which message this delta is for.

metadata
map<any> | null
role
string | null
tool_call_id
string | null
tool_calls
array<ToolCall> | null
ToolCall
function
FunctionCall* required
FunctionCall
arguments
map<any> | string* required
name
string* required
id
string
index
integer

Default Value: 0

type
"function"
ChatCompletionResponseChoiceLogprobs
ChatCompletionResponseTokenLogprobsTopK
bytes
array<integer>* required
logprob
number* required
token
string* required
token_id
integer* required
top_logprobs
array<ChatCompletionResponseTokenLogprobs> | null
ChatCompletionResponseTokenLogprobs
bytes
array<integer>* required
logprob
number* required
token
string* required
token_id
integer* required
created
integer* required

Example:

1702256327
id
string* required

Example:

cmpl-e5cc70bb28c444948073e77776eb30ef
model
string* required

Example:

codestral-latest
object
string* required

Example:

chat.completion
usage
UsageInfo* required
UsageInfo
completion_tokens
integer

Default Value: 0

prompt_audio_seconds
integer | null
prompt_tokens
integer

Default Value: 0

prompt_tokens_details
PromptTokensDetails | null

Token usage details for the prompt.

PromptTokensDetails

Token usage details for the prompt.

audio_tokens
integer

Default Value: 0

cached_tokens
integer

Default Value: 0

service_tier
string | null

The service tier at which the request was processed: standard or priority.

total_tokens
integer

Default Value: 0