Completaciones de Chat
Solicitud y respuesta de POST /v1/chat/completions.
Completaciones de Chat
Solicitud
POST https://apimaster.ai/v1/chat/completions
Cabeceras
| Cabecera | Necesaria | Notas |
|---|---|---|
Authorization |
Sí | Bearer YOUR_API_KEY |
Content-Type |
Sí | application/json |
Cuerpo (campos comunes)
| Campo | Tipo | Notas |
|---|---|---|
model |
string | p.ej. claude-sonnet-4-6 |
messages |
array | {role, content} |
max_tokens |
number | Máximo de tokens de completación |
temperature |
number | Opcional |
stream |
boolean | Streaming SSE |
Ejemplo
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
}'
Respuesta sin streaming
{
"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
Con "stream": true, el cuerpo es text/event-stream; las líneas son data: {json} hasta data: [DONE].
Códigos de estado
| Código | Significado |
|---|---|
| 400 | Parámetros incorrectos |
| 401 | Autenticación fallida |
| 402 / 403 | Cuota o permiso |
| 429 | Límite de tasa excedido |
| 502 / 503 | Error del servidor ascendente — reintentar |