Chat Completions
Erstellen Sie Chat-Vervollständigungsantworten. Unterstützt Textgenerierung, multimodale Eingaben, Function Calling, Streaming und mehr.
Für neue Projekte empfehlen wir die Responses API. Die Responses API trennt instructions von input, sodass Systemanweisungen automatisch von Prompt Caching profitieren – mit höherer Cache-Trefferquote sowie deutlich geringeren Kosten und Latenzen. Chat Completions wird weiterhin langfristig unterstützt; bestehende Integrationen müssen nicht migriert werden.
Endpunkt
POST https://api.ofox.ai/v1/chat/completionsAnfrageparameter
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
curl https://api.ofox.ai/v1/chat/completions \
-H "Authorization: Bearer $OFOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-6.1-sol",
"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-6.1-sol",
"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 = client.chat.completions.create(
model="openai/gpt-6.1-sol",
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-6.1-sol",
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-6.1-sol, anthropic/claude-sonnet-5.5, google/gemini-3.8-flash u.a.
Siehe Anleitung zum Bildverständnis.
Function Calling
Siehe Function Calling-Anleitung.