İçeriğe geç
API Referansı
API Referansı

OpenAI Chat Completions

RunAPI'nin OpenAI uyumlu Chat Completions işlemi aracılığıyla bir istek gönderin.

01

Genel Bakış

RunAPI'nin OpenAI uyumlu Chat Completions işlemini, uyumlu bir model ve protokolün istek ile yanıt şekilleriyle kullanın.

Hızlı başlangıç

  1. Bir API anahtarı oluşturun ve RUNAPI_API_KEY olarak ayarlayın.
  2. Uyumlu bir model seçin, ardından belgelenen yol parametrelerini ve JSON gövdesini gönderin.
  3. Bu işlem için gösterilen JSON yanıtını veya sunucu tarafından gönderilen olayları okuyun ve protokol hatalarını işleyin.

Uç Nokta

POST /v1/chat/completions
Temel URL
https://runapi.ai
Sözleşme sürümü
v1
Tercih edilen kimlik doğrulama
Authorization: Bearer YOUR_API_TOKEN
02

Kimlik doğrulama taşıyıcıları

RunAPI aşağıda listelenen her taşıyıcıyı kabul eder. Oluşturulan örnekler, protokolün tercih ettiği başlığı kullanır.

header - Tercih edilen
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
header
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

Uyumlu modeller

Güncel fiyatlandırma, hız sınırları ve ticari kullanım ayrıntıları için bir model sayfası açın.

60 uyumlu modeli göster
04

İstek sözleşmesi

JSON gövdesi

Yalnızca hem genel protokol hem de RunAPI destek kanıtı olan alanlar listelenmektedir. Ek JSON gövde alanları doğrudan iletilir.

JSON gövdesi9 alan
max_tokens["integer", "null"]
İsteğe bağlı

Desteklenen modeller için saklanan uyumluluk üretim token sınırı; model desteği farklılık gösterebilir.

messagesarray
Zorunlu

OpenAI Chat Completions biçiminde konuşma iletileri.

messages[].content["string", "array"]
İsteğe bağlı
messages[].rolestring
Zorunlu
modelstring
Zorunlu

Uyumlu model kataloğu tarafından döndürülen RunAPI model tanımlayıcısı.

stream["boolean", "null"]
İsteğe bağlı

Chat Completions parçalarını sunucu tarafından gönderilen olaylar olarak döndür.

Varsayılan: false
temperature["number", "null"]
İsteğe bağlı

Örnekleme sıcaklığı; model desteği değişiklik gösterebilir.

toolsarray
İsteğe bağlı

Modelin çağırabileceği araçlar.

top_p["number", "null"]
İsteğe bağlı

Çekirdek örnekleme olasılığı; model desteği farklılık gösterebilir.

İstek örneği

JSON
{
  "messages": [
    {
      "content": "Summarize one practical improvement for an API deployment.",
      "role": "user"
    }
  ],
  "model": "gpt-5.4",
  "stream": false
}
05

Eş zamanlı yanıt

HTTP 200

Şema

JSON
{
  "additionalProperties": true,
  "properties": {
    "choices": {
      "type": "array"
    },
    "created": {
      "type": "integer"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "object": {
      "const": "chat.completion",
      "type": "string"
    },
    "usage": {
      "additionalProperties": true,
      "properties": {
        "completion_tokens": {
          "type": "integer"
        },
        "prompt_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ],
      "type": "object"
    }
  },
  "required": [
    "id",
    "object",
    "created",
    "model",
    "choices"
  ],
  "type": "object"
}

Örnek

JSON
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Hello! How can I help today?",
        "role": "assistant"
      }
    }
  ],
  "created": 1785196800,
  "id": "chatcmpl_example",
  "model": "gpt-5.4",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 8,
    "prompt_tokens": 12,
    "total_tokens": 20
  }
}
06

SSE olayı: chunk

text/event-stream

Şema

JSON
{
  "additionalProperties": true,
  "properties": {
    "choices": {
      "type": "array"
    },
    "created": {
      "type": "integer"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "object": {
      "const": "chat.completion.chunk",
      "type": "string"
    },
    "usage": {
      "oneOf": [
        {
          "additionalProperties": true,
          "properties": {
            "completion_tokens": {
              "type": "integer"
            },
            "prompt_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "prompt_tokens",
            "completion_tokens",
            "total_tokens"
          ],
          "type": "object"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "object",
    "choices"
  ],
  "type": "object"
}

Örnek

JSON
{
  "choices": [
    {
      "delta": {
        "content": "Hello"
      },
      "finish_reason": null,
      "index": 0
    }
  ],
  "id": "chatcmpl_example",
  "object": "chat.completion.chunk",
  "usage": null
}
07

Protokol hatası: invalid_request

HTTP 400

Şema

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "message": {
          "type": "string"
        },
        "param": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "message",
        "type"
      ],
      "type": "object"
    }
  },
  "required": [
    "error"
  ],
  "type": "object"
}

Örnek

JSON
{
  "error": {
    "code": null,
    "message": "messages is required",
    "param": "messages",
    "type": "invalid_request_error"
  }
}
08

Kullanım

Şema

JSON
{
  "additionalProperties": true,
  "properties": {
    "completion_tokens": {
      "type": "integer"
    },
    "prompt_tokens": {
      "type": "integer"
    },
    "total_tokens": {
      "type": "integer"
    }
  },
  "required": [
    "prompt_tokens",
    "completion_tokens",
    "total_tokens"
  ],
  "type": "object"
}

Örnek

JSON
{
  "completion_tokens": 8,
  "prompt_tokens": 12,
  "total_tokens": 20
}
09

Oluşturulan Kod Örnekleri

Her cURL, JavaScript ve Python örneği, protokole özgü bir SDK gerektirmeden bu sözleşmedeki doğrulanmış isteği gönderir.

Yükle

Shell
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1/chat/completions",
    headers={"Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"model": "gpt-5.4", "messages": [{"role": "user", "content": "Summarize one practical improvement for an API deployment."}], "stream": False}
)
response.raise_for_status()
print(response.json())