/v1/chat/completions
Sohbet tamamlamaları oluşturun
OpenAI uyumlu API kullanarak sohbet tamamlamaları oluşturun. ustaGPT'de mevcut tüm LLM modelleriyle çalışır.
/v1/chat/completionsİstek Örnekleri
curl https://api.ustagpt.com.tr/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false
}'Akış Yanıtları
Gerçek zamanlı yanıtlar için stream: true parametresini kullanın.
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.ustagpt.com.tr/v1"
)
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a poem about AI"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Parametreler
| Ad | Tip | Gerekli | Açıklama |
|---|---|---|---|
model | string | Evet | Kullanılacak model ID'si (örn: gpt-4o) |
messages | array | Evet | Sohbetteki mesaj dizisi |
stream | boolean | Hayır | Yanıtların akış olarak alınıp alınmayacağı |
temperature | number | Hayır | Örnekleme sıcaklığı (0-2) |
max_tokens | integer | Hayır | Oluşturulacak maksimum token sayısı |
tools | array | Hayır | Modelin çağırabileceği araç/fonksiyon tanımları dizisi. Model metin yerine tool_calls dizisi döner. |
tool_choice | string | object | Hayır | Araç seçimini kontrol eder: "auto" (varsayılan), "none", "required" veya tek bir aracı zorlamak için {"type":"function","function":{"name":"…"}}. |
parallel_tool_calls | boolean | Hayır | Modelin tek mesajda birden fazla araç çağrısı üretip üretemeyeceği (varsayılan: true). |
response_format | object | Hayır | Çıktı biçimini zorlar: {"type":"text"}, {"type":"json_object"} veya {"type":"json_schema","json_schema":{…}}. |
top_p | number | Hayır | Çekirdek örnekleme olasılık kütlesi (0-1). temperature alternatifi. |
stop | string | array | Hayır | Üretimi durduran bir string veya en fazla 4 elemanlı bir string dizisi. |
stream_options | object | Hayır | Akış seçenekleri. SSE akışının sonunda yalnızca kullanım bilgisi içeren bir parça almak için {"include_usage": true} gönderin. Bunu kullanmazsanız akış yanıtları token kullanımı taşımaz. |
presence_penalty, frequency_penalty | number | Hayır | Tokenların varlık/sıklığını ayarlar (-2.0 ile 2.0 arası). |
seed, logprobs, top_logprobs | number | boolean | Hayır | Deterministik örnekleme tohumu ve token başına log olasılıkları (top_logprobs ile birlikte). |
Araç Çağırma (Tool Calling)
ustaGPT üzerindeki tüm kodlama modelleri OpenAI uyumlu fonksiyon çağırmayı destekler. Araçlarınızı tools dizisinde tanımlayın; model, çalıştırmanız gereken bir tool_calls dizisiyle yanıt verir.
curl https://api.ustagpt.com.tr/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"messages": [
{"role": "user", "content": "What is the weather in Istanbul?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}'Model bir araç çağırmayı seçtiğinde finish_reason tool_calls olur ve message.content null olur. Sonucu tool rolüyle ve eşleşen tool_call_id ile messages dizisine ekleyip konuşmayı tekrar gönderin; nihai yanıtı alırsınız.
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "claude-sonnet-4-5-20250929",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Istanbul\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 82,
"completion_tokens": 24,
"total_tokens": 106
}
}Akış Modunda Token Kullanımı
Akış yanıtları siz istemedikçe kullanım bilgisi içermez. prompt_tokens, completion_tokens ve total_tokens içeren son bir parça almak için stream_options.include_usage gönderin. Bu, akış isteklerinin panelinizde doğru faturalanmasını sağlar.
curl -N https://api.ustagpt.com.tr/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true,
"stream_options": {"include_usage": true}
}'Dördüncü parçaya dikkat: choices boştur ve yalnızca usage doludur, ardından [DONE] gelir.
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant","content":"He"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"gpt-4o","choices":[{"index":0,"delta":{"content":"llo"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"gpt-4o","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"gpt-4o","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":2,"total_tokens":11}}
data: [DONE]Desteklenen Modeller
Sohbet tamamlamaları için bazı popüler modeller:
- gpt-5.6-sol, gpt-5.5-pro, gpt-4o
- claude-opus-5, claude-sonnet-4-5-20250929
- gemini-3.6-flash, gemini-3.1-pro-preview
- deepseek-v4-pro, qwen3.8-max, glm-5.2, kimi-k3