Create FIM Completion (Beta)
POST/completions
The FIM (Fill-In-the-Middle) Completion API.
User must set base_url="https://api.deepseek.com/beta"
to use this feature.
Request
- application/json
Body
required
- MOD1
- MOD2
Array [
]
Possible values: [deepseek-chat
]
ID of the model to use.
Default value: Once upon a time,
The prompt to generate completions for.
Echo back the prompt in addition to the completion
Possible values: >= -2
and <= 2
Default value: 0
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
Possible values: <= 20
Include the log probabilities on the logprobs
most likely output tokens, as well the chosen tokens. For example, if logprobs
is 20, the API will return a list of the 20 most likely tokens. The API will always return the logprob
of the sampled token, so there may be up to logprobs+1
elements in the response.
The maximum value for logprobs
is 20.
The maximum number of tokens that can be generated in the completion.
Possible values: >= -2
and <= 2
Default value: 0
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
stop
object
nullable
Up to 16 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
oneOf
string
string
Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE]
message. Example Python code.
stream_options
object
nullable
Options for streaming response. Only set this when you set stream: true
.
If set, an additional chunk will be streamed before the data: [DONE]
message. The usage
field on this chunk shows the token usage statistics for the entire request, and the choices
field will always be an empty array. All other chunks will also include a usage
field, but with a null value.
The suffix that comes after a completion of inserted text.
Possible values: <= 2
Default value: 1
What sampling temperature to use, between 0 and 2. Higher values like 0.8 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.
Possible values: <= 1
Default value: 1
An alternative to sampling with temperature, called 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
- 200
OK
- application/json
- Schema
- Example (from schema)
Schema
Array [
]
A unique identifier for the completion.
choices
object[]
required
The list of completion choices the model generated for the input prompt.
Possible values: [stop
, length
, content_filter
, insufficient_system_resource
]
The reason the model stopped generating tokens. This will be stop
if the model hit a natural stop point or a provided stop sequence,
length
if the maximum number of tokens specified in the request was reached,
content_filter
if content was omitted due to a flag from our content filters,
or insufficient_system_resource
if the request is interrupted due to insufficient resource of the inference system.
logprobs
object
nullable
required
The Unix timestamp (in seconds) of when the completion was created.
The model used for completion.
This fingerprint represents the backend configuration that the model runs with.
Possible values: [text_completion
]
The object type, which is always "text_completion"
usage
object
Usage statistics for the completion request.
Number of tokens in the generated completion.
Number of tokens in the prompt. It equals prompt_cache_hit_tokens + prompt_cache_miss_tokens.
Number of tokens in the prompt that hits the context cache.
Number of tokens in the prompt that misses the context cache.
Total number of tokens used in the request (prompt + completion).
completion_tokens_details
object
Breakdown of tokens used in a completion.
Tokens generated by the model for reasoning.
{
"id": "string",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": {
"text_offset": [
0
],
"token_logprobs": [
0
],
"tokens": [
"string"
],
"top_logprobs": [
{}
]
},
"text": "string"
}
],
"created": 0,
"model": "string",
"system_fingerprint": "string",
"object": "text_completion",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"reasoning_tokens": 0
}
}
}