Skip to Content
API-ReferenzOpenAI-kompatibles ProtokollChat Completions

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/completions

Anfrageparameter

ParameterTypErforderlichBeschreibung
modelstringModellkennung, z.B. openai/gpt-4o
messagesarrayNachrichtenarray
temperaturenumberSampling-Temperatur 0-2, Standard 1
max_tokensnumberMaximale Anzahl generierter Tokens
streambooleanStreaming-Antwort aktivieren
top_pnumberNucleus-Sampling-Parameter
frequency_penaltynumberFrequenzstrafe -2 bis 2
presence_penaltynumberPräsenzstrafe -2 bis 2
toolsarrayVerfügbare Tool-Definitionen (Function Calling)
tool_choicestring/objectTool-Auswahlstrategie
response_formatobjectAntwortformat (JSON Mode)
providerobjectOfoxAI-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

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:

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