Chat Completions
Create chat completion responses. Supports text generation, multimodal input, Function Calling, streaming, and more.
Endpoint
POST https://api.ofox.ai/v1/chat/completionsRequest Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Model identifier, e.g. openai/gpt-4o |
messages | array | ✅ | Message array |
temperature | number | — | Sampling temperature 0-2, default 1 |
max_tokens | number | — | Maximum tokens to generate |
stream | boolean | — | Enable streaming response |
top_p | number | — | Nucleus sampling parameter |
frequency_penalty | number | — | Frequency penalty -2 to 2 |
presence_penalty | number | — | Presence penalty -2 to 2 |
tools | array | — | Tool definitions (Function Calling) |
tool_choice | string/object | — | Tool selection strategy |
response_format | object | — | Response format (JSON Mode) |
provider | object | — | OfoxAI extension: routing and fallback config |
Message Format
interface Message {
role: 'system' | 'user' | 'assistant' | 'tool'
content: string | ContentPart[] // Text or multimodal content
name?: string
tool_calls?: ToolCall[] // Tool calls in assistant messages
tool_call_id?: string // Call ID in tool messages
}
// Multimodal content
type ContentPart =
| { type: 'text'; text: string }
| { type: 'image_url'; image_url: { url: string; detail?: 'auto' | 'low' | 'high' } }Request Examples
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": "You are a helpful assistant."},
{"role": "user", "content": "Explain what an API Gateway is"}
],
"temperature": 0.7
}'Response Format
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1703123456,
"model": "openai/gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "An API Gateway is a..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}Streaming
Set stream: true to enable SSE streaming responses:
Python
stream.py
stream = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)Streaming Response Format
Each chunk is sent via SSE:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" there"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Multimodal Input (Vision)
Send images for model analysis:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
)Models with vision capabilities include openai/gpt-4o, anthropic/claude-sonnet-4.5, google/gemini-3-flash-preview, and more.
See the Vision guide for details.
Function Calling
See the Function Calling guide for details.
Last updated on