> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openserv.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat completions

> POST /v1/chat/completions — OpenAI-format chat completions through SERV.

```
POST https://inference-api.openserv.ai/v1/chat/completions
```

OpenAI Chat Completions format. The universal endpoint — works with every model in the [catalog](../models).

## Request

<ParamField header="Authorization" type="string" required>
  `Bearer $SERV_API_KEY`.
</ParamField>

<ParamField body="model" type="string" required>
  Model ID from the [catalog](../models), for example `gpt-5.4-mini`.
</ParamField>

<ParamField body="messages" type="array" required>
  The conversation so far. Must include a system or developer message. Each entry has a `role` (`system`, `user`, `assistant`, or `tool`) and `content`.
</ParamField>

<ParamField body="max_completion_tokens" type="integer">
  Maximum number of tokens to generate.
</ParamField>

<ParamField body="reasoning_effort" type="string">
  Reasoning depth for reasoning-capable models.
</ParamField>

<ParamField body="temperature" type="number">
  Sampling temperature.
</ParamField>

<ParamField body="tools" type="array">
  Function definitions, in OpenAI format: `{ type: "function", function: { name, parameters } }`.
</ParamField>

<ParamField body="tool_choice" type="string | object">
  `"auto"`, `"none"`, or `{ type: "function", function: { name } }`.
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Stream the response as server-sent events.
</ParamField>

All other OpenAI Chat Completions parameters are accepted and forwarded to the model.

## Response

<ResponseField name="id" type="string">
  Unique identifier for the completion.
</ResponseField>

<ResponseField name="object" type="string">
  Always `"chat.completion"`.
</ResponseField>

<ResponseField name="model" type="string">
  The model used to generate the completion.
</ResponseField>

<ResponseField name="choices" type="array">
  The generated completions. `choices[0].message.content` holds the text.

  <Expandable title="Choice object">
    <ResponseField name="index" type="integer">
      Position of this choice in the array.
    </ResponseField>

    <ResponseField name="message" type="object">
      Contains `role` (`"assistant"`) and `content`.
    </ResponseField>

    <ResponseField name="finish_reason" type="string">
      One of `stop`, `length`, `content_filter`, or `tool_calls`.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  Token counts: `prompt_tokens`, `completion_tokens`, `total_tokens`.
</ResponseField>

<RequestExample>
  ```bash curl theme={null}
  curl https://inference-api.openserv.ai/v1/chat/completions \
    -H "Authorization: Bearer $SERV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-5.4-mini",
      "messages": [
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Hello!"}
      ]
    }'
  ```

  ```js OpenAI SDK theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://inference-api.openserv.ai/v1",
    apiKey: process.env.SERV_API_KEY,
  });

  const completion = await client.chat.completions.create({
    model: "gpt-5.4-mini",
    messages: [
      { role: "system", content: "You are a concise assistant." },
      { role: "user", content: "Hello!" },
    ],
  });
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "id": "chatcmpl-...",
    "object": "chat.completion",
    "model": "gpt-5.4-mini",
    "choices": [
      {
        "index": 0,
        "message": { "role": "assistant", "content": "Hello! How can I help?" },
        "finish_reason": "stop"
      }
    ],
    "usage": { "prompt_tokens": 18, "completion_tokens": 7, "total_tokens": 25 }
  }
  ```
</ResponseExample>
