Een chat completion maken
Gebruik CometAPI POST /v1/chat/completions om gesprekken met meerdere berichten naar chatmodellen te sturen, met bedieningselementen voor streaming, temperature en max_tokens.
model te wijzigen; de meeste OpenAI-compatibele SDK’s werken door base_url in te stellen op https://api.cometapi.com/v1.
Berichtrollen
Multimodale invoer verzenden
Veel modellen ondersteunen afbeeldingen en audio naast tekst. Gebruik de arrayindeling voorcontent om multimodale berichten te verzenden:
detail bepaalt de diepgang van afbeeldingsanalyse:
low— sneller, gebruikt minder tokens (vaste kosten)high— gedetailleerde analyse, meer tokens verbruiktauto— het model beslist (standaard)
Antwoorden streamen
Stelstream in op true om incrementele uitvoer te ontvangen. Het antwoord wordt geleverd als Server-Sent Events (SSE), waarbij elk event een object chat.completion.chunk bevat:
Gestructureerde uitvoer aanvragen
Gebruikresponse_format om het model te dwingen geldige JSON terug te geven die overeenkomt met een specifiek schema:
json_schema) garandeert dat de uitvoer exact overeenkomt met je schema. De JSON Object-modus (json_object) garandeert alleen geldige JSON — de structuur wordt niet afgedwongen.Tools en functies aanroepen
Geef tooldefinities op om het model externe functies te laten aanroepen:finish_reason: "tool_calls" en bevat de array message.tool_calls de functienaam en argumenten. Vervolgens voer je de functie uit en stuur je het resultaat terug als een bericht tool met de overeenkomende tool_call_id.
Opmerkingen over providers
Parameterondersteuning bij providers
Parameterondersteuning bij providers
max_tokens versus max_completion_tokens
max_tokens versus max_completion_tokens
max_tokens— De verouderde parameter. Werkt met de meeste modellen, maar is verouderd voor nieuwere OpenAI-modellen.max_completion_tokens— De aanbevolen parameter voor modellen van GPT-4.1, de GPT-5-serie en o-series. Vereist voor reasoning-modellen, omdat deze zowel uitvoertokens als reasoning-tokens omvat.
system versus developer-rol
system versus developer-rol
system— De traditionele instructierol. Werkt met alle modellen.developer— Geïntroduceerd met modellen van o1. Biedt sterkere opvolging van instructies voor nieuwere modellen. Valt bij oudere modellen terug op het gedrag vansystem.
developer voor nieuwe projecten die gericht zijn op modellen van GPT-4.1+ of o-series.Veelgestelde vragen
Hoe ga je om met rate limits?
Implementeer exponential backoff wanneer je429 Too Many Requests tegenkomt:
Hoe behoud je gesprekscontext?
Neem de volledige gesprekshistorie op in de arraymessages:
Wat betekent finish_reason?
Hoe beheers je kosten?
- Gebruik
max_completion_tokensom de uitvoerlengte te beperken. - Gebruik
gpt-5.6-terravoor een balans tussen intelligentie en kosten, ofgpt-5.6-lunavoor efficiënte workloads met hoge volumes. - Houd Prompts beknopt — vermijd overbodige context.
- Controleer het tokengebruik in het antwoordveld
usage.
Autorisaties
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 Respons
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"