Skip to main content

Last Update: 2025/3/26

Deepseek Chat Completion API

The Deepseek Chat Completion API allows you to generate conversational responses using Deepseek's language models. This document provides an overview of the API endpoints, request parameters, and response structure.

Endpoint

POST https://platform.llmprovider.ai/v1/chat/completions

Request Headers

HeaderValue
AuthorizationBearer YOUR_API_KEY
Content-Typeapplication/json

Request Body

The request body should be a JSON object with the following parameters:

ParameterTypeDescription
modelstringThe model to use (e.g., deepseek-chat).
messagesarrayA list of message objects representing the conversation history.
frequency_penaltynumber(Optional) Penalty for new tokens based on their frequency in the text so far. Required: -2 <= x <= 2
max_tokensinteger(Optional) The maximum number of tokens to generate.
presence_penaltynumber(Optional) Penalty for new tokens based on their presence in the text so far. Required: -2 <= x <= 2
response_formatobject(Optional) An object specifying the format that the model must output.
stoparray(Optional) Up to 4 sequences where the API will stop generating further tokens.
streamboolean(Optional) Whether to stream the response as it is generated.
temperaturenumber(Optional) What sampling temperature to use, Required: 0 <= x <= 2.
top_pnumber(Optional) Top-p sampling probability. Required: 0 <= x <= 1
toolsarray(Optional) A list of tools the model may call.
tools_choiceobject(Optional)Controls which (if any) tool is called by the model.
logprobsbool(Optional) Whether to return log probabilities of the output tokens or not.
top_logprobsinteger(Optional) An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. Required: 0 <= x <= 20

Example Request

{
"messages": [
{
"content": "You are a helpful assistant",
"role": "system"
},
{
"content": "Hi",
"role": "user"
}
],
"model": "deepseek-chat",
"frequency_penalty": 0,
"max_tokens": 2048,
"presence_penalty": 0,
"response_format": {
"type": "text"
},
"stop": null,
"stream": false,
"stream_options": null,
"temperature": 1,
"top_p": 1,
"tools": null,
"tool_choice": "none",
"logprobs": false,
"top_logprobs": null
}

Response Body

The response body will be a JSON object containing the generated completions and other metadata.

FieldTypeDescription
idstringUnique identifier for the completion.
objectstringThe type of object returned, usually chat.completion.
createdintegerTimestamp of when the completion was created.
modelstringThe model used for the completion.
choicesarrayA list of generated completion choices.
usageobjectToken usage statistics for the request.
system_fingerprintstringThis fingerprint represents the backend configuration that the model runs with.

Example Response

{
"id": "0aa5ca3a-2fc0-42c3-a247-fe5897a45d46",
"object": "chat.completion",
"created": 1738923553,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today? 😊"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 11,
"total_tokens": 20,
"prompt_tokens_details": {
"cached_tokens": 0
},
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 9
},
"system_fingerprint": "fp_3a5770e1b4"
}

Example Request

curl -X POST https://platform.llmprovider.ai/v1/chat/completions \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'

For more details, refer to the Deepseek API documentation.