Chat Completions
Çok mesajlı konuşmalar göndermek ve Streaming, temperature ve max_tokens kontrolleriyle LLM yanıtları almak için CometAPI POST /v1/chat/completions kullanın.
CometAPI, Chat Completions isteklerini tek bir OpenAI uyumlu arayüz üzerinden OpenAI, Claude ve Gemini dahil olmak üzere birden fazla sağlayıcıya yönlendirir.Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
model parametresini değiştirerek modeller arasında geçiş yapın; çoğu OpenAI uyumlu SDK, base_url değerini https://api.cometapi.com/v1 olarak ayarlayarak çalışır.
Mesaj rolleri
| Role | Description |
|---|---|
system | Asistanın davranışını ve kişiliğini belirler. Konuşmanın başına yerleştirilir. |
developer | Daha yeni modeller için system yerine geçer (o1+). Kullanıcı girişinden bağımsız olarak modelin uyması gereken talimatları sağlar. |
user | Son kullanıcıdan gelen mesajlar. |
assistant | Önceki model yanıtları, konuşma geçmişini korumak için kullanılır. |
tool | Araç/fonksiyon çağrılarından gelen sonuçlar. Orijinal araç çağrısıyla eşleşen tool_call_id içermelidir. |
Multimodal input gönderin
Birçok model, metnin yanında görselleri ve sesi de destekler. Multimodal mesajlar göndermek içincontent için dizi formatını kullanın:
detail parametresi görsel analiz derinliğini kontrol eder:
low— daha hızlıdır, daha az token kullanır (sabit maliyet)high— ayrıntılı analiz, daha fazla token tüketilirauto— modele karar verdirir (varsayılan)
Yanıtları stream edin
Artımlı çıktı almak içinstream değerini true olarak ayarlayın. Yanıt, her olayın bir chat.completion.chunk nesnesi içerdiği Server-Sent Events (SSE) olarak iletilir:
Yapılandırılmış çıktı isteyin
Modeli belirli bir şemaya uyan geçerli JSON döndürmeye zorlamak içinresponse_format kullanın:
json_schema), çıktının şemanızla tam olarak eşleşmesini garanti eder. JSON Object modu (json_object) yalnızca geçerli JSON olmasını garanti eder — yapı zorunlu kılınmaz.Araçları ve işlevleri çağırın
Modelin harici işlevleri çağırmasını etkinleştirmek için araç tanımlarını sağlayın:finish_reason: "tool_calls" olur ve message.tool_calls dizisi işlev adını ve argümanları içerir. Ardından işlevi çalıştırır ve sonucu eşleşen tool_call_id ile bir tool mesajı olarak geri gönderirsiniz.
Sağlayıcılar arası notlar
Sağlayıcılar arasında parametre desteği
Sağlayıcılar arasında parametre desteği
| Parameter | OpenAI GPT | Claude (via compat) | Gemini (via compat) |
|---|---|---|---|
temperature | 0–2 | 0–1 | 0–2 |
top_p | 0–1 | 0–1 | 0–1 |
n | 1–128 | yalnızca 1 | 1–8 |
stop | En fazla 4 | En fazla 4 | En fazla 5 |
tools | ✅ | ✅ | ✅ |
response_format | ✅ | ✅ (json_schema) | ✅ |
logprobs | ✅ | ❌ | ❌ |
reasoning_effort | o-series, GPT-5.1+ | ❌ | ❌ (Gemini native için thinking kullanın) |
max_tokens ve max_completion_tokens
max_tokens ve max_completion_tokens
max_tokens— Eski parametre. Çoğu modelle çalışır ancak daha yeni OpenAI modelleri için kullanımdan kaldırılmıştır.max_completion_tokens— GPT-4.1, GPT-5 serisi ve o-series modelleri için önerilen parametre. Hem output tokens hem de reasoning tokens içerdiği için reasoning modelleri için gereklidir.
system ve developer role
system ve developer role
system— Geleneksel talimat rolü. Tüm modellerle çalışır.developer— o1 modelleriyle tanıtılmıştır. Daha yeni modeller için daha güçlü talimat takibi sağlar. Eski modellerdesystemdavranışına geri döner.
developer kullanın.SSS
Oran limitleri nasıl ele alınır?
429 Too Many Requests ile karşılaştığınızda, üstel geri çekilme uygulayın:
Konuşma bağlamı nasıl korunur?
Tam konuşma geçmişinimessages dizisine ekleyin:
finish_reason ne anlama gelir?
| Değer | Anlam |
|---|---|
stop | Doğal olarak tamamlandı veya bir stop sequence tetiklendi. |
length | max_tokens veya max_completion_tokens sınırına ulaşıldı. |
tool_calls | Model bir veya daha fazla araç/fonksiyon çağrısı yaptı. |
content_filter | Çıktı, içerik politikası nedeniyle filtrelendi. |
Maliyetler nasıl kontrol edilir?
- Çıktı uzunluğunu sınırlamak için
max_completion_tokenskullanın. - Maliyet açısından verimli modeller seçin (ör. daha basit görevler için
gpt-5.4-miniveyagpt-5.4-nano). - Prompt’ları kısa tutun — gereksiz bağlamdan kaçının.
usageyanıt alanındaki token kullanımını izleyin.
Yetkilendirmeler
Bearer token authentication. Use your CometAPI key.
Gövde
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 Yanıt
Successful chat completion response.
Unique completion identifier.
"chatcmpl-abc123"
chat.completion "chat.completion"
Unix timestamp of creation.
1774412483
The model used (may include version suffix).
"gpt-5.4-2025-07-16"
Array of completion choices.
"default"
"fp_490a4ad033"