Complétions de chat
Requête et réponse pour POST /v1/chat/completions.
Complétions de chat
Requête
POST https://apimaster.ai/v1/chat/completions
En-têtes
| En-tête | Requis | Notes |
|---|---|---|
Authorization |
Oui | Bearer YOUR_API_KEY |
Content-Type |
Oui | application/json |
Corps (champs courants)
| Champ | Type | Notes |
|---|---|---|
model |
string | ex. claude-sonnet-4-6 |
messages |
array | {role, content} |
max_tokens |
number | Nombre maximum de tokens de complétion |
temperature |
number | Optionnel |
stream |
boolean | Diffusion SSE |
Exemple
curl -s "https://apimaster.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{"role": "system", "content": "You are helpful."},
{"role": "user", "content": "Say hi in one word."}
],
"max_tokens": 64
}'
Réponse non streamée
{
"id": "chatcmpl-...",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
}
}
Streaming
Avec "stream": true, le corps est text/event-stream ; les lignes sont data: {json} jusqu'à data: [DONE].
Codes de statut
| Code | Signification |
|---|---|
| 400 | Paramètres incorrects |
| 401 | Échec d'authentification |
| 402 / 403 | Quota ou permission |
| 429 | Limite de débit atteinte |
| 502 / 503 | Erreur du service en amont |