Skip to main content

Chat completion

POST/v1/chat/completions

The /chat/completions route allows you to generate a response from a conversational exchange structured as messages (system, user, assistant). It is suited for simple chatbot use cases, with a clear history and a schema similar to early OpenAI APIs.

Warning

This route is gradually being replaced by /responses, which is more flexible and more complete.

Structure

Each request must include a JSON similar to:

Request body
{
"model": "ClovisLLM",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Explain what an API is." }
],
"temperature": 0.7,
"max_tokens": 2000
}

Field description

FieldTypeRequiredDescription
modelint✔️Model name
messagesarray✔️Message history
temperaturefloatCreativity (0 = deterministic)
max_tokensintMaximum number of generated tokens
top_pfloatNucleus sampling
nintNumber of responses
streambooleanEnable response streaming
stopstringarrayStop token(s)
presence_penaltyfloatDiscourages topic repetition
frequency_penaltyfloatDiscourages word repetition
userstringUser identifier
response_formatobject{ "type": "json_object"}, to enforce a well-formed response.

API Response

Main response object

FieldTypeDescription
idstringUnique request identifier (useful for debugging / logs).
objectstringReturned object type ("chat.completion").
createdint (timestamp)UNIX timestamp (in seconds).
modelstringThe model actually used.
choicesarrayList of generated completions (one or more).
usageobjectToken usage details.
system_fingerprintstring (optional)Internal model identifier (useful for debugging).

Details of the choices field

FieldTypeDescription
indexintResponse index (0 = first).
messageobject{ "role": "assistant", "content": "…" } – the actual model response.
finish_reasonstringReason why generation stopped (see table below).
provider_specific_fieldsobjectBackend metadata (latency, actual model, etc.).

Values of finish_reason

ValueMeaning
stopResponse completed naturally (end of text or logical completion).
lengthStopped because the max_tokens limit was reached.
content_filterStopped due to a safety / moderation filter.
function_callFunction/tool call (function calling API).
tool_callsSame but using the tools format.
nullPartial streaming or internal error.

Details of the usage field

FieldTypeDescription
prompt_tokensintNumber of tokens used for the request (input messages).
completion_tokensintNumber of tokens generated in the response.
total_tokensintSum of the two above.

Details of the message object

FieldTypeDescription
rolestringMessage role: system, user, assistant, function, tool.
contentstringMessage content (what the role says).

What is the role field used for?

ValueSpeakerTypical usageExample
systemThe designer / assistant frameworkSets the context, tone, and behavior rules of the model."You are a Clovis assistant, always polite and concise."
userThe end userMessage sent by the human (question, request, instruction)."Explain what an Azure blob is."
assistantThe modelRepresents the model’s previous response (used to maintain history)."An Azure blob is a data storage object..."
functionFunction result (legacy syntax)Output of a function called by the model (replaced by tool in newer versions)."Search result: 3 documents found."
toolExternal tool resultUsed in function calling or external API calls.{"title":"Report.pdf"}

Quick summary

Response body
{
"id": "string",
"object": "chat.completion",
"created": 1700000000,
"model": "ClovisLLM",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "…" },
"finish_reason": "stop",
"provider_specific_fields": { /* … */ }
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 456,
"total_tokens": 579
},
"system_fingerprint": "optional-string"
}

(Fields may vary slightly depending on the API provider: OpenAI, Azure, Anthropic, etc.)

Usage examples

curl https://llm-gateway.clovis-ai.fr/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer sk-xxxxxxxx"
-d '{
"model": "ClovisLLM",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain what an API is."}
],
"temperature": 0.7
}'