Eine Chat Completion erstellen
Verwenden Sie CometAPI POST /v1/chat/completions, um Unterhaltungen mit mehreren Nachrichten an Chat-Modelle mit Steuerung für Streaming, temperature und max_tokens zu senden.
model ändern; die meisten OpenAI-kompatiblen SDKs funktionieren, wenn base_url auf https://api.cometapi.com/v1 gesetzt wird.
Nachrichtenrollen
Multimodal-Eingaben senden
Viele Modelle unterstützen neben Text auch Bilder und Audio. Verwenden Sie zum Senden von Multimodal-Nachrichten das Array-Format fürcontent:
detail steuert die Analysetiefe für Bilder:
low— schneller, verwendet weniger Tokens (feste Kosten)high— detaillierte Analyse, verbraucht mehr Tokensauto— das Modell entscheidet (Standard)
Antworten streamen
Um inkrementelle Ausgaben zu erhalten, setzen Siestream auf true. Die Antwort wird als Server-Sent Events (SSE), wobei jedes Ereignis ein chat.completion.chunk-Objekt enthält:
Strukturierte Ausgabe anfordern
Um das Modell dazu zu zwingen, gültiges JSON zurückzugeben, das einem bestimmten Schema entspricht, verwenden Sieresponse_format:
json_schema) garantiert, dass die Ausgabe exakt Ihrem Schema entspricht. Der JSON-Object-Modus (json_object) garantiert nur gültiges JSON – die Struktur wird nicht erzwungen.Tools und Funktionen aufrufen
Um dem Modell den Aufruf externer Funktionen zu ermöglichen, stellen Sie Tool-Definitionen bereit:finish_reason: "tool_calls", und das Array message.tool_calls enthält den Funktionsnamen und die Argumente. Führen Sie anschließend die Funktion aus und senden Sie das Ergebnis als tool-Nachricht mit dem passenden tool_call_id zurück.
Hinweise anbieterübergreifend
Parameterunterstützung bei verschiedenen Anbietern
Parameterunterstützung bei verschiedenen Anbietern
max_tokens im Vergleich zu max_completion_tokens
max_tokens im Vergleich zu max_completion_tokens
max_tokens— Der Legacy-Parameter. Funktioniert mit den meisten Modellen, ist aber für neuere OpenAI-Modelle veraltet.max_completion_tokens— Der empfohlene Parameter für GPT-4.1, die GPT-5-Serie und o-series-Modelle. Für Reasoning-Modelle erforderlich, da er sowohl Ausgabe-Tokens als auch Reasoning-Tokens umfasst.
system- im Vergleich zur developer-Rolle
system- im Vergleich zur developer-Rolle
system— Die traditionelle Anweisungsrolle. Funktioniert mit allen Modellen.developer— Mit o1-Modellen eingeführt. Bietet für neuere Modelle eine stärkere Befolgung von Anweisungen. Fällt bei älteren Modellen auf das Verhalten vonsystemzurück.
developer für neue Projekte, die auf GPT-4.1+- oder o-series-Modelle ausgerichtet sind.FAQ
Wie gehe ich mit Ratenlimits um?
Implementieren Sie bei Auftreten von429 Too Many Requests exponentielles Backoff:
Wie kann der Unterhaltungskontext erhalten werden?
Fügen Sie den vollständigen Unterhaltungsverlauf in das Arraymessages ein:
Was bedeutet finish_reason?
Wie lassen sich Kosten kontrollieren?
- Verwenden Sie
max_completion_tokens, um die Ausgabelänge zu begrenzen. - Verwenden Sie
gpt-5.6-terrafür ein Gleichgewicht zwischen Leistungsfähigkeit und Kosten odergpt-5.6-lunafür effiziente Workloads mit hohem Volumen. - Halten Sie Prompts prägnant – vermeiden Sie redundanten Kontext.
- Überwachen Sie die Token-Nutzung im Antwortfeld
usage.
Autorisierungen
Bearer token authentication. Use your CometAPI key.
Body
Model ID to use for this request. See the Models page for current options.
"gpt-4.1"
A list of messages forming the conversation. Each message has a role (system, user, assistant, or developer) and content (text string or multimodal content array).
If true, partial response tokens are delivered incrementally via server-sent events (SSE). The stream ends with a data: [DONE] message.
Sampling temperature between 0 and 2. Higher values (e.g., 0.8) produce more random output; lower values (e.g., 0.2) make output more focused and deterministic. Recommended to adjust this or top_p, but not both.
0 <= x <= 2Nucleus sampling parameter. The model considers only the tokens whose cumulative probability reaches top_p. For example, 0.1 means only the top 10% probability tokens are considered. Recommended to adjust this or temperature, but not both.
0 <= x <= 1Number of completion choices to generate for each input message. Defaults to 1.
Up to 4 sequences where the API will stop generating further tokens. Can be a string or an array of strings.
Maximum number of tokens to generate in the completion. The total of input + output tokens is capped by the model's context length.
Number between -2.0 and 2.0. Positive values penalize tokens based on whether they have already appeared, encouraging the model to explore new topics.
-2 <= x <= 2Number between -2.0 and 2.0. Positive values penalize tokens proportionally to how often they have appeared, reducing verbatim repetition.
-2 <= x <= 2A JSON object mapping token IDs to bias values from -100 to 100. The bias is added to the model's logits before sampling. Values between -1 and 1 subtly adjust likelihood; -100 or 100 effectively ban or force selection of a token.
A unique identifier for your end-user. Helps with abuse detection and monitoring.
An upper bound for the number of tokens to generate, including visible output tokens and reasoning tokens. Use this instead of max_tokens for GPT-4.1+, GPT-5 series, and o-series models.
Specifies the output format. Use {"type": "json_object"} for JSON mode, or {"type": "json_schema", "json_schema": {...}} for strict structured output.
A list of tools the model may call. Currently supports function type tools.
Controls how the model selects tools. auto (default): model decides. none: no tools. required: must call a tool.
Whether to return log probabilities of the output tokens.
Number of most likely tokens to return at each position (0-20). Requires logprobs to be true.
0 <= x <= 20Controls the reasoning effort for o-series and GPT-5.1+ models.
low, medium, high Options for streaming. Only valid when stream is true.
Specifies the processing tier.
auto, default, flex, priority Antwort
Successful chat completion response.
Unique completion identifier.
"chatcmpl-abc123"
Object type. Non-streaming responses use chat.completion.
chat.completion "chat.completion"
Unix timestamp of creation.
1774412483
The model used (may include version suffix).
"gpt-5.4-2026-03-05"
Array of completion choices.
Token accounting for this request. Billing uses these counts.
Service tier that processed the request, when the provider reports one.
"default"
Provider backend configuration fingerprint, when the provider reports one.
"fp_490a4ad033"