fimCompletion

Sends a Fill-In-the-Middle (FIM) completion request to the DeepSeek API.

This function handles the low-level API communication for FIM completions, which allow the model to complete text given a prompt (and optionally a suffix).

Example:

val params = fimCompletionParams { suffix = "# End of function" }
val request = params.createRequest("def calculate_area(radius):")
val completion = client.fimCompletion(request)
println(completion.choices.first().text)

Return

A FIMCompletion containing the model's response

Parameters

request

The FIM completion request containing all parameters

Throws

if the API returns a non-2xx status


Creates a fully customizable FIM completion request using a builder pattern.

This approach gives you complete control over all aspects of the FIM request, including prompt, suffix, and generation parameters.

Example:

val completion = client.fimCompletion {
prompt("public class Calculator {")
params {
suffix = "}"
temperature = 0.8
maxTokens = 500
}
}
println(completion.choices.first().text)

Return

A FIMCompletion containing the model's response

Parameters

block

A builder block for constructing the complete request

Throws

if the API returns a non-2xx status


Streams a fully customizable FIM completion using a builder pattern.

This approach gives you complete control over all aspects of the streaming FIM request through a dedicated builder pattern.

Example:

client.fimCompletion {
prompt("public interface DataProcessor {")
params {
suffix = "}"
temperature = 0.8
maxTokens = 300
}
}.collect { chunk ->
print(chunk.choices.firstOrNull()?.text ?: "")
}

Return

A Flow of FIMCompletion objects representing the streaming response

Parameters

block

A builder block for constructing the complete streaming request

Throws

from the returned Flow's collector if the API returns a non-2xx status