Chat Completions

Chat completion API

The Chat Completions API lets you build conversation-based AI applications. By sending message history, you get contextual and consistent responses.

POST /v1/chat/completions

Generates a model response for the given message history.

Request Body

model string required

The ID of the model to use. Example: openai/gpt-4o-mini, anthropic/claude-sonnet-4

messages array required

An array of messages containing the conversation history. Each message must include the role and content fields.

temperature number optional

A value between 0 and 2. Higher values produce more creative responses, lower values more consistent ones. Default: 0.7

max_tokens integer optional

The maximum number of tokens to generate in the response.

stream boolean optional

When set to true, responses are streamed in real time as Server-Sent Events. Default: false

top_p number optional

The nucleus sampling parameter. Between 0 and 1. Default: 1

Message Roles

Role Description
system A system instruction that defines the assistant's behavior
user Messages from the user
assistant The assistant's previous responses

Example Request

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 asistansın."
      },
      {
        "role": "user",
        "content": "Python'da liste nasıl oluşturulur?"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 500
  }'

Example Response

JSON
{
  "id": "req_a1b2c3d4e5f6a1b2c3d4e5f6",
  "object": "chat.completion",
  "created": 1706000000,
  "model": "openai/gpt-4o-mini",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Python'da liste oluşturmanın birkaç yolu vardır:\n\n1. Köşeli parantez ile:\n```python\nmy_list = [1, 2, 3, 4, 5]\n```\n\n2. list() fonksiyonu ile:\n```python\nmy_list = list((1, 2, 3))\n```"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 95,
    "total_tokens": 123
  },
  "cost": {
    "amount": 0.000061,
    "currency": "USD"
  }
}
Want help finding the right model?