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.
/v1/chat/completions
Generates a model response for the given message history.
Request Body
The ID of the model to use. Example: openai/gpt-4o-mini, anthropic/claude-sonnet-4
An array of messages containing the conversation history. Each message must include the role and content fields.
A value between 0 and 2. Higher values produce more creative responses, lower values more consistent ones. Default: 0.7
The maximum number of tokens to generate in the response.
When set to true, responses are streamed in real time as Server-Sent Events. Default: false
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 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
{
"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"
}
}