POST /v1/chat/completions
Usage
Cet endpoint lance une nouvelle demande de chat.
Requete
http
POST /v1/chat/completions
Authorization: Bearer km_your_token_here
Content-Type: application/jsonCorps minimal
json
{
"model": "group:123e4567-e89b-12d3-a456-426614174000",
"messages": [
{
"role": "user",
"content": "Resume ce document."
}
]
}Champs pris en charge
| Champ | Type | Obligatoire | Notes |
|---|---|---|---|
model | string | oui | format group:<uuid> |
messages | array | oui | doit contenir au moins un message user |
stream | boolean | non | active le mode SSE |
max_tokens | integer | non | limite de sortie |
max_completion_tokens | integer | non | limite de sortie prioritaire |
temperature | number | non | entre 0 et 2 |
metadata | object | non | accepte notamment request_id et mode |
Reponse standard
En mode non streaming, la reponse suit la forme generale suivante:
json
{
"id": "chatcmpl_123",
"object": "chat.completion",
"created": 1712345678,
"model": "group:123e4567-e89b-12d3-a456-426614174000",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Voici le resume."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 120,
"completion_tokens": 84,
"total_tokens": 204
},
"kitemesh": {
"execution_id": "3e6f4f5d-c02a-4cae-b35d-e83420867962",
"credits_charged": 3,
"request_id": "req_demo_001"
}
}Reponse avec approbation d’outils
Si la demande exige une approbation avant execution d’outils, la reponse non stream peut ressembler a ceci:
json
{
"id": "chatcmpl_123",
"object": "chat.completion",
"created": 1712345678,
"model": "group:123e4567-e89b-12d3-a456-426614174000",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "1fb2fd25-8f78-412a-a0b8-7976e3700fc4",
"type": "function",
"function": {
"name": "create_ticket",
"arguments": "{\"priority\":\"high\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"kitemesh": {
"approval_id": "86dd028d-6f5c-4f13-83db-d4fe9bc5b865",
"execution_id": "3e6f4f5d-c02a-4cae-b35d-e83420867962",
"expires_at": "2026-06-08T16:20:00.000Z"
}
}Conservez approval_id. Il sera necessaire pour POST /v1/chat/resume.
Streaming SSE
Quand stream vaut true, l’API renvoie des evenements SSE.
Exemple de chunk texte:
json
{
"id": "chatcmpl_123",
"object": "chat.completion.chunk",
"created": 1712345678,
"model": "group:123e4567-e89b-12d3-a456-426614174000",
"choices": [
{
"index": 0,
"delta": {
"content": "Voici "
},
"finish_reason": null
}
]
}Exemple de chunk d’approbation:
json
{
"id": "chatcmpl_123",
"object": "chat.completion.chunk",
"created": 1712345678,
"model": "group:123e4567-e89b-12d3-a456-426614174000",
"choices": [
{
"index": 0,
"delta": {
"tool_calls": [
{
"id": "1fb2fd25-8f78-412a-a0b8-7976e3700fc4",
"type": "function",
"function": {
"name": "create_ticket",
"arguments": "{\"priority\":\"high\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"kitemesh": {
"approval_id": "86dd028d-6f5c-4f13-83db-d4fe9bc5b865",
"execution_id": "3e6f4f5d-c02a-4cae-b35d-e83420867962",
"expires_at": "2026-06-08T16:20:00.000Z",
"request_id": "req_demo_001"
}
}La fin du flux est marquee par:
text
data: [DONE]