cURL ile API Kullanımı

Terminal üzerinden doğrudan API çağrıları

cURL, komut satırından HTTP istekleri göndermenizi sağlayan güçlü bir araçtır. Onysoft API'yi test etmek ve entegre etmek için en basit yöntemdir.

Temel İstek

Aşağıdaki örnek, basit bir chat completion isteği gönderir:

cURL
curl https://api.onysoft.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ony-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [
      {"role": "user", "content": "Merhaba, nasılsın?"}
    ]
  }'

System Prompt ile İstek

cURL
curl https://api.onysoft.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ony-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [
      {"role": "system", "content": "Sen yardımcı bir Türkçe asistansın."},
      {"role": "user", "content": "Python nedir?"}
    ],
    "temperature": 0.7,
    "max_tokens": 500
  }'

Streaming ile İstek

Gerçek zamanlı yanıt almak için stream: true parametresini ekleyin:

cURL
curl https://api.onysoft.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ony-your-api-key" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [{"role": "user", "content": "Merhaba!"}],
    "stream": true
  }'
info

Not: Streaming için -N (--no-buffer) flag'ini kullanın. Bu, cURL'ün çıktıyı tamponlamadan doğrudan göstermesini sağlar.

Bakiye Sorgulama

cURL
curl https://api.onysoft.com/v1/balance \
  -H "Authorization: Bearer sk-ony-your-api-key"

Modelleri Listeleme

cURL
curl https://api.onysoft.com/v1/models \
  -H "Authorization: Bearer sk-ony-your-api-key"

Windows'ta cURL Kullanımı

Windows Command Prompt veya PowerShell'de JSON gönderirken tırnak işaretlerine dikkat edin:

Windows CMD
curl https://api.onysoft.com/v1/chat/completions ^
  -H "Authorization: Bearer sk-ony-your-api-key" ^
  -H "Content-Type: application/json" ^
  -d "{\"model\": \"openai/gpt-4o-mini\", \"messages\": [{\"role\": \"user\", \"content\": \"Merhaba\"}]}"
warning

Windows kullanıcıları: Satır devam karakteri olarak ^ kullanın. JSON içindeki tırnak işaretlerini \" ile escape edin.

Size uygun modeli bulmanıza yardımcı olayım mı?