Bir chat completion oluşturun
Streaming, structured output ve tool calling özellikleriyle chat modellerine çok mesajlı konuşmalar göndermek için CometAPI POST /v1/chat/completions kullanın.
base_url="https://api.cometapi.com/v1" ve CometAPI API anahtarınızla yapılandırın.
Temel, görüntü, Streaming ve structured-output örnekleri gpt-6-astra kullanır. Function Calling örneği gpt-5.6-sol, log-probability örneği ise gpt-4.1 kullanır.
Mesaj rolleri
Multimodal girdi gönderme
Metinle birlikte görüntü göndermek için bir content part dizisi kullanın:image_url.detail kullanın. Bu örnek high kullanır.
Yanıtları akış olarak alın
Artımlı çıktı almak içinstream değerini true olarak ayarlayın. Yanıt şu şekilde gönderilir: Sunucu Tarafından Gönderilen Olaylar (SSE). Metin, chat.completion.chunk nesneleri içinde gelir; bu kısaltılmış örnek son kullanım parçasını içerir:
Yapılandırılmış çıktı isteyin
Yapılandırılmış çıktı istemek içinresponse_format kullanın:
Araçları ve işlevleri çağırma
Bir işlev tanımıyla birliktegpt-5.6-sol kullanın:
finish_reason: "tool_calls" ve bir message.tool_calls dizisi döndürür. İşlevin JSON ile kodlanmış arguments değerini ayrıştırın, işlevinizi yürütün, ardından assistant mesajını ve eşleşen tool değerini içeren bir tool_call_id sonuç mesajını ekleyin.
İstek parametrelerini seçme
Modele özgü parametreler
Modele özgü parametreler
reasoning_effort ve max_completion_tokens ile GPT-6 Astra kullanın. Functions ve Logprobs örnekleri sırasıyla gpt-5.6-sol ve gpt-4.1 için istek seçeneklerini gösterir.Claude veya Gemini’ye özgü istek biçimleri için bkz. Anthropic Messages ve Gemini Generate content.max_tokens ve max_completion_tokens
max_tokens ve max_completion_tokens
max_completion_tokens değerini, GPT-6 Astra örnekleri için üretilen token’ları sınırlamak üzere kullanın. Buna reasoning ve görünür çıktı dahildir; bu nedenle her ikisi için de yeterli alan bırakın. max_tokens eski bir parametredir.Yönerge rolleri
Yönerge rolleri
developer değerini, GPT-6 Astra örneklerindeki uygulama yönergeleri için kullanın. Son kullanıcı içeriğini user mesajlarında tutun ve bir konuşmaya devam ederken önceki assistant yanıtlarını koruyun.SSS
Hız sınırları nasıl ele alınır?
429 Too Many Requests ile karşılaşıldığında üstel geri çekilme uygulayın:
Konuşma bağlamı nasıl korunur?
Konuşma geçmişinin tamamınımessages dizisine ekleyin:
finish_reason ne anlamagelir?
Maliyetler nasıl kontrol edilir?
- Çıktı uzunluğunu sınırlamak için
max_completion_tokenskullanın. - Model fiyatlandırmalarını karşılaştırın ve iş yükü gereksinimlerinizi karşılayan bir model seçin.
- 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-6-astra"
Conversation messages, including instructions, user input, assistant replies, and tool results.
If true, partial response tokens are delivered incrementally via server-sent events (SSE). The stream ends with a data: [DONE] message.
Sampling temperature. Omit this field for GPT-6 Astra.
0 <= x <= 2Nucleus sampling threshold. Omit this field for GPT-6 Astra. For sampling overrides, adjust either top_p or temperature.
0 <= x <= 1Number of completion choices to generate for each input message. Defaults to 1.
Stop string or list of up to four strings, for models that support stop sequences.
Legacy output-token limit. Use max_completion_tokens for the GPT-6 Astra examples.
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.
Maximum generated tokens, including visible output and reasoning. Leave enough room for both, as in the image-input example.
Specifies the output format. Use {"type": "json_object"} for JSON mode, or {"type": "json_schema", "json_schema": {...}} for strict structured output.
Function definitions for a model that supports tool calling on Chat Completions. The function example uses GPT-5.6 Sol; use Responses for GPT-6 Astra tool calls.
Controls how the model selects tools. auto (default): model decides. none: no tools. required: must call a tool.
Return token log probabilities. Use gpt-4.1 as shown in the Logprobs example.
Number of most likely tokens to return at each position (0-20). Requires logprobs to be true.
0 <= x <= 20Reasoning effort supported by the selected model. The GPT-6 Astra examples use low; the GPT-5.6 Sol function example uses none. See the model reference for other supported levels.
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_example"
Object type. Non-streaming responses use chat.completion.
chat.completion "chat.completion"
Unix timestamp of creation.
1788763703
The model used (may include version suffix).
"gpt-6-astra"
Array of completion choices.
Token accounting for this request. Billing uses these counts.
Service tier that processed the request, when returned.
Model configuration fingerprint, when returned.