Chat Completions
Erstellen Sie Chat-Vervollständigungsantworten. Unterstützt Textgenerierung, multimodale Eingaben, Function Calling, Streaming und mehr.
Endpunkt
POST https://api.ofox.ai/v1/chat/completionsAnfrageparameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
model | string | ✅ | Modellkennung, z.B. openai/gpt-4o |
messages | array | ✅ | Nachrichtenarray |
temperature | number | — | Sampling-Temperatur 0-2, Standard 1 |
max_tokens | number | — | Maximale Anzahl generierter Tokens |
stream | boolean | — | Streaming-Antwort aktivieren |
top_p | number | — | Nucleus-Sampling-Parameter |
frequency_penalty | number | — | Frequenzstrafe -2 bis 2 |
presence_penalty | number | — | Präsenzstrafe -2 bis 2 |
tools | array | — | Verfügbare Tool-Definitionen (Function Calling) |
tool_choice | string/object | — | Tool-Auswahlstrategie |
response_format | object | — | Antwortformat (JSON Mode) |
provider | object | — | OfoxAI-Erweiterung: Routing- und Failover-Konfiguration |
Message-Format
interface Message {
role: 'system' | 'user' | 'assistant' | 'tool'
content: string | ContentPart[] // Text oder multimodaler Inhalt
name?: string
tool_calls?: ToolCall[] // Tool-Aufrufe in Assistant-Nachrichten
tool_call_id?: string // Aufruf-ID für Tool-Nachrichten
}
// Multimodaler Inhalt
type ContentPart =
| { type: 'text'; text: string }
| { type: 'image_url'; image_url: { url: string; detail?: 'auto' | 'low' | 'high' } }Anfragebeispiele
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": "Sie sind ein hilfreicher Assistent."},
{"role": "user", "content": "Erklären Sie, was ein API Gateway ist"}
],
"temperature": 0.7
}'Antwortformat
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1703123456,
"model": "openai/gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Ein API Gateway ist ein..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}Streaming-Antwort
Setzen Sie stream: true, um eine SSE-Streaming-Antwort zu aktivieren:
Python
stream.py
stream = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Erzählen Sie eine Geschichte"}],
stream=True
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)Streaming-Antwortformat
Jeder Chunk wird über SSE gesendet:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hallo"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" Welt"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Multimodale Eingabe (Vision)
Senden Sie Bilder zur Analyse durch das Modell:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Was ist auf diesem Bild zu sehen?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
)Modelle mit Vision-Unterstützung: openai/gpt-4o, anthropic/claude-sonnet-4.5, google/gemini-3-flash-preview u.a.
Siehe Anleitung zum Bildverständnis.
Function Calling
Siehe Function Calling-Anleitung.
Last updated on