Chat Completions
Cree respuestas de completación de chat. Soporta generación de texto, entrada multimodal, llamada a funciones, respuesta en streaming y más.
Endpoint
POST https://api.ofox.ai/v1/chat/completionsParámetros de solicitud
| Parámetro | Tipo | Obligatorio | Descripción |
|---|---|---|---|
model | string | ✅ | Identificador del modelo, p. ej. openai/gpt-4o |
messages | array | ✅ | Array de mensajes |
temperature | number | — | Temperatura de muestreo 0-2, por defecto 1 |
max_tokens | number | — | Número máximo de tokens a generar |
stream | boolean | — | Activar respuesta en streaming |
top_p | number | — | Parámetro de muestreo nucleus |
frequency_penalty | number | — | Penalización de frecuencia -2 a 2 |
presence_penalty | number | — | Penalización de presencia -2 a 2 |
tools | array | — | Definición de herramientas (Function Calling) |
tool_choice | string/object | — | Estrategia de selección de herramientas |
response_format | object | — | Formato de respuesta (JSON Mode) |
provider | object | — | Extensión OfoxAI: configuración de enrutamiento y respaldo |
Formato de Message
interface Message {
role: 'system' | 'user' | 'assistant' | 'tool'
content: string | ContentPart[] // Texto o contenido multimodal
name?: string
tool_calls?: ToolCall[] // Llamadas a herramientas del mensaje assistant
tool_call_id?: string // ID de llamada del mensaje tool
}
// Contenido multimodal
type ContentPart =
| { type: 'text'; text: string }
| { type: 'image_url'; image_url: { url: string; detail?: 'auto' | 'low' | 'high' } }Ejemplo de solicitud
cURL
Terminal
curl https://api.ofox.ai/v1/chat/completions \
-H "Authorization: Bearer $OFOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{"role": "system", "content": "Eres un asistente útil."},
{"role": "user", "content": "Explica qué es un API Gateway"}
],
"temperature": 0.7
}'Formato de respuesta
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1703123456,
"model": "openai/gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Un API Gateway es un..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}Respuesta en streaming
Active la respuesta en streaming SSE con stream: true:
Python
stream.py
stream = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Cuéntame una historia"}],
stream=True
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)Formato de respuesta en streaming
Cada chunk se envía mediante SSE:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hola"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" mundo"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Entrada multimodal (visión)
Envíe imágenes para que el modelo las analice:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "¿Qué hay en esta imagen?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
)Los modelos con capacidad de visión incluyen: openai/gpt-4o, anthropic/claude-sonnet-4.5, google/gemini-3-flash-preview, entre otros.
Consulte la guía de comprensión visual.
Function Calling
Consulte la guía de llamada a funciones.
Last updated on