chatCompletion

Sends a chat completion request to the DeepSeek API.

This is a low-level function that handles the direct HTTP communication with the API. Most users will prefer the higher-level chat functions instead.

Example:

val request = ChatCompletionRequest(
model = "deepseek-chat",
messages = listOf(UserMessage("Hello!"))
)
val response = client.chatCompletion(request)

Return

A ChatCompletion containing the model's response

Parameters

request

The fully configured request object containing all parameters for the API call


Sends a fully customizable chat completion request.

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

Example:

val response = client.chatCompletion {
model = "deepseek-chat"
messages {
system("You are a Kotlin expert")
user("How do I use flow in Kotlin?")
}
temperature = 0.7
maxTokens = 2000
frequencyPenalty = 0.5
}

Return

A ChatCompletion containing the model's response

Parameters

block

A builder block for constructing the complete request


Streams a fully customizable chat completion request.

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

Example:

client.chatCompletion {
model = "deepseek-chat"
messages {
system("You are an expert programmer")
user("Show me how to implement a binary search tree in Kotlin")
}
temperature = 0.7
maxTokens = 2000
}.collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}

Return

A Flow of ChatCompletionChunk objects representing the streaming response

Parameters

block

A builder block for constructing the complete streaming request