Chat Completions
Menu
Chat

Chat Completions

Generate a model response for a conversation in the OpenAI Chat Completions format.

POST /v1/chat/completions

The most widely supported endpoint. It is compatible with the OpenAI Chat Completions API and works for every chat model on RuToken — including Claude, Gemini and other providers, whose requests are converted automatically.

Authentication

Authorization: Bearer sk-xxxx

Request body

Parameter Type Required Description
model string Yes Model ID, e.g. gpt-4o-mini. See List models.
messages array Yes Conversation so far. See Messages below.
stream boolean No Stream the response as SSE. See Streaming. Default false.
stream_options object No Streaming options. {"include_usage": true} adds a final chunk with token usage.
temperature number No Sampling temperature, 0–2. Higher is more random.
top_p number No Nucleus sampling, 0–1. Change this or temperature, not both.
max_tokens integer No Maximum number of tokens to generate.
max_completion_tokens integer No Upper bound for generated tokens including reasoning tokens. Preferred for reasoning models (o-series, gpt-5).
stop string | array No Up to 4 sequences where generation stops.
n integer No Number of choices to generate. Default 1.
presence_penalty number No -2.0–2.0. Positive values encourage new topics.
frequency_penalty number No -2.0–2.0. Positive values reduce verbatim repetition.
seed integer No Best-effort deterministic sampling.
response_format object No Output format. See Structured output below.
tools array No Functions the model may call. See Tool calling below.
tool_choice string | object No none, auto, required, or {"type": "function", "function": {"name": "..."}}.
parallel_tool_calls boolean No Allow several tool calls in one turn.
reasoning_effort string No Reasoning models only: minimal, low, medium, high.
logprobs boolean No Return log probabilities of output tokens.
top_logprobs integer No 0–20 most likely tokens per position. Requires logprobs: true.
logit_bias object No Map of token ID to bias -100–100.
modalities array No Output modalities for models that support them, e.g. ["text", "audio"].
audio object No Audio output settings (voice, format) when modalities includes audio.
user string No Stable end-user identifier, for abuse monitoring.

Not every upstream model supports every parameter. Unsupported parameters are usually ignored or rejected by the provider with a 400. Explicit values such as "temperature": 0 are passed through as-is.

Messages

Each message has a role and content.

Role Description
system / developer Instructions for the model. developer is the newer name used by reasoning models.
user Input from the end user.
assistant Previous model replies. May contain tool_calls.
tool Result of a tool call. Requires tool_call_id.

content is either a string or an array of content parts:

Part type Fields Description
text text Plain text.
image_url image_url.url, image_url.detail Image as an https:// URL or data:image/...;base64, URI. detail: auto, low, high.
input_audio input_audio.data, input_audio.format Base64 audio, format wav or mp3.
file file.file_data, file.filename Base64 file such as a PDF, for models that accept files.
json
{
  "role": "user",
  "content": [
    {"type": "text", "text": "What is in this picture?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg", "detail": "auto"}}
  ]
}

Tool calling

Describe functions with JSON Schema:

json
{
  "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"
}

When the model decides to call a function, the response has finish_reason: "tool_calls" and message.tool_calls. Run the function, then send the result back as a tool message with the matching tool_call_id.

Structured output

response_format.type Description
text Default free text.
json_object Valid JSON. Ask for JSON in the prompt too.
json_schema JSON that matches json_schema.schema. Set json_schema.strict: true for strict adherence.
json
{
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "city",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {"name": {"type": "string"}, "country": {"type": "string"}},
        "required": ["name", "country"],
        "additionalProperties": false
      }
    }
  }
}

Request example

cURL
curl https://rutoken.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain recursion in one sentence."}
    ],
    "temperature": 0.7,
    "max_tokens": 200
  }'
Python
from openai import OpenAI

client = OpenAI(base_url="https://rutoken.ai/v1", api_key="sk-xxxx")
resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain recursion in one sentence."},
    ],
    temperature=0.7,
    max_tokens=200,
)
print(resp.choices[0].message.content)
Node.js
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://rutoken.ai/v1", apiKey: "sk-xxxx" });
const resp = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Explain recursion in one sentence." },
  ],
  temperature: 0.7,
  max_tokens: 200,
});
console.log(resp.choices[0].message.content);

Response

json
{
  "id": "chatcmpl-AbC123",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "gpt-4o-mini",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Recursion is when a function solves a problem by calling itself on smaller versions of the same problem."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 21,
    "total_tokens": 46
  }
}
Field Type Description
choices[].message.content string Generated text. null when the model only calls tools.
choices[].message.tool_calls array Tool calls requested by the model.
choices[].message.reasoning_content string Reasoning text, for models that return it (e.g. DeepSeek R1).
choices[].finish_reason string stop, length, tool_calls or content_filter.
usage object Token counts used for billing: prompt_tokens, completion_tokens, total_tokens.

Streaming

Set "stream": true to receive chat.completion.chunk events ending with data: [DONE]. See Streaming for the format and client code, and Errors for error handling.