Dokümantasyona Dön

/v1/chat/completions

Sohbet tamamlamaları oluşturun

OpenAI uyumlu API kullanarak sohbet tamamlamaları oluşturun. ustaGPT'de mevcut tüm LLM modelleriyle çalışır.

POST/v1/chat/completions

İstek Örnekleri

cURL
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.

Streaming Example (Python)
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

AdTipGerekliAçıklama
modelstringEvetKullanılacak model ID'si (örn: gpt-4o)
messagesarrayEvetSohbetteki mesaj dizisi
streambooleanHayırYanıtların akış olarak alınıp alınmayacağı
temperaturenumberHayırÖrnekleme sıcaklığı (0-2)
max_tokensintegerHayırOluşturulacak maksimum token sayısı
toolsarrayHayırModelin çağırabileceği araç/fonksiyon tanımları dizisi. Model metin yerine tool_calls dizisi döner.
tool_choicestring | objectHayırAraç seçimini kontrol eder: "auto" (varsayılan), "none", "required" veya tek bir aracı zorlamak için {"type":"function","function":{"name":"…"}}.
parallel_tool_callsbooleanHayırModelin tek mesajda birden fazla araç çağrısı üretip üretemeyeceği (varsayılan: true).
response_formatobjectHayırÇıktı biçimini zorlar: {"type":"text"}, {"type":"json_object"} veya {"type":"json_schema","json_schema":{…}}.
top_pnumberHayırÇekirdek örnekleme olasılık kütlesi (0-1). temperature alternatifi.
stopstring | arrayHayırÜretimi durduran bir string veya en fazla 4 elemanlı bir string dizisi.
stream_optionsobjectHayırAkış 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_penaltynumberHayırTokenların varlık/sıklığını ayarlar (-2.0 ile 2.0 arası).
seed, logprobs, top_logprobsnumber | booleanHayırDeterministik ö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.

Tool calling
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.

Response
{
  "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.

Streaming with usage
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.

SSE response
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