# POST /v1/chat/completions - i14 Chat Completions API

> Create a chat completion with Sugar Glider. Accepts a messages array and model ID, returns generated text with usage stats.

Source: https://i14.ai/docs/api-reference/chat-completions/

The `/v1/chat/completions` endpoint is the primary way to generate text with i14 models. Send a conversation as a messages array and receive the model’s response. The endpoint is fully OpenAI-compatible, so any client library that targets the OpenAI Chat API works with i14 by updating the base URL and API key.

## Endpoint

```text
POST https://api.i14.ai/v1/chat/completions
```

## Request Headers

| Header          | Required | Value                 |
| --------------- | -------- | --------------------- |
| `Authorization` | Yes      | `Bearer YOUR_API_KEY` |
| `Content-Type`  | Yes      | `application/json`    |

## Request Body Parameters

`model` (string, required)

The ID of the model to use for this completion. Choose an ID returned by [Models](https://i14.ai/docs/api-reference/models/). The examples use Sugar Glider. A model your key cannot use returns `403` with the error code `model_not_allowed`.

`messages` (array, required)

An array of message objects representing the conversation history. Each message has a `role`. Include text in `content` for ordinary messages. In a tool conversation the assistant may provide `tool_calls` instead of text.

* `role` (string): The author of the message. Use `"system"`, `"user"`, or `"assistant"` for chat, and `"tool"` to return a [function result](https://i14.ai/docs/api-usage/function-calling/#chat-completions) where supported.
* `content` (string or array): The text content of the message. Sugar Glider (`i14-sugarglider-nemotron3-super-120b-v1`) accepts text only. It does not support image input.

`temperature` (number)

Sampling temperature between `0.0` and `2.0`. Higher values produce more random output; lower values make responses more focused and deterministic. **Default:** `1.0`

`max_tokens` (integer)

The maximum number of tokens to generate in the completion. Thinking tokens count toward this limit, so set it high enough for both the thinking and the answer. The request will be cut off once this limit is reached. Set this explicitly. Defaults can vary with the model deployment.

`max_completion_tokens` (integer)

An alternative output token limit for Chat Completions. Send one of `max_completion_tokens` or `max_tokens`, not both.

`stream_options` (object)

With `stream: true`, set `include_usage: true` to request the final token totals. Usage may be missing if the stream is interrupted.

`tools` (array)

[Function definitions](https://i14.ai/docs/api-usage/function-calling/#chat-completions) that a compatible model can call. The client executes the function and sends its result in a new request.

`tool_choice` (string or object)

Control whether a compatible model can call a function. Start with `"auto"` to let the model decide or `"none"` to disable calls. Forced choices depend on model and parser support.

`chat_template_kwargs` (object)

On compatible reasoning models, pass `enable_thinking: true` to request a thinking phase. Some clients pass this extension through their SDK’s extra-body option.

`n` (integer)

The number of generated choices. Use `1` for Sugar Glider; some deployments do not support multiple choices.

`stream` (boolean)

When `true`, the response is delivered as a stream of [Server-Sent Events (SSE)](https://i14.ai/docs/api-usage/streaming/) rather than a single JSON object. Each event contains a partial completion delta. **Default:** `false`

`top_p` (number)

Nucleus sampling probability mass. The model considers only the tokens comprising the top `top_p` probability mass at each step. Use this **or** `temperature`, not both. **Default:** `1.0`

`stop` (string or array)

Up to four sequences where the model will stop generating further tokens. The returned text will not include the stop sequence itself. Pass a single string or an array of strings.

`presence_penalty` (number)

A value between `-2.0` and `2.0`. Positive values penalize tokens that have already appeared in the text, increasing the model’s likelihood to introduce new topics. **Default:** `0`

`frequency_penalty` (number)

A value between `-2.0` and `2.0`. Positive values penalize tokens based on how frequently they have appeared so far, reducing repetitive phrasing. **Default:** `0`

## Example Request

* cURL

  macOS and Linux (bash or zsh)

  ```bash
  curl --request POST \
    --url https://api.i14.ai/v1/chat/completions \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "i14-sugarglider-nemotron3-super-120b-v1",
      "messages": [
        {
          "role": "system",
          "content": "You are a helpful assistant."
        },
        {
          "role": "user",
          "content": "Explain what a transformer model is in one sentence."
        }
      ],
      "temperature": 0.7,
      "max_tokens": 2048
    }'
  ```

* Python

  ```python
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_API_KEY",
      base_url="https://api.i14.ai/v1",
  )

  response = client.chat.completions.create(
      model="i14-sugarglider-nemotron3-super-120b-v1",
      messages=[
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Explain what a transformer model is in one sentence."},
      ],
      temperature=0.7,
      max_tokens=2048,
  )

  print(response.choices[0].message.content)
  ```

* Node.js

  ```javascript
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: "YOUR_API_KEY",
    baseURL: "https://api.i14.ai/v1",
  });

  const response = await client.chat.completions.create({
    model: "i14-sugarglider-nemotron3-super-120b-v1",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "Explain what a transformer model is in one sentence." },
    ],
    temperature: 0.7,
    max_tokens: 2048,
  });

  console.log(response.choices[0].message.content);
  ```

## Response Fields

`id` (string)

The completion identifier. Treat it as opaque.

`object` (string)

The object type. Always `"chat.completion"`.

`created` (integer)

The Unix timestamp (in seconds) of when the completion was created.

`model` (string)

The model ID that was used to generate this completion.

`choices` (array)

An array of completion choice objects. The examples request one choice.

Choice object properties

`index` (integer)

The zero-based index of this choice within the `choices` array.

`message.role` (string)

The role of the author of this message. Always `"assistant"` for generated completions.

`message.content` (string)

Generated answer text. It can be empty or null, for example when the assistant calls a function or no answer fits the token budget.

`message.tool_calls` (array)

Function calls requested by the assistant, when supported. Each has an ID, a function name and a JSON-encoded arguments string.

`message.reasoning_content` (string)

Reasoning text, if the model emits it separately. Do not require this field in a client.

`finish_reason` (string)

The reason generation stopped. Possible values:

* `"stop"` - the model hit a natural stopping point or a stop sequence
* `"length"` - the output limit was reached
* `"tool_calls"` - the model requested a tool call, where supported

`usage` (object)

Token consumption statistics for this request.

Usage object properties

`prompt_tokens` (integer)

The number of tokens in the input messages.

`completion_tokens` (integer)

The number of tokens in the generated completion.

`total_tokens` (integer)

The sum of `prompt_tokens` and `completion_tokens`.

`completion_tokens_details.reasoning_tokens` (integer)

The number of completion tokens spent on reasoning.

`x_i14_perf` (object)

Optional i14-specific performance metrics, when present, such as `tokens_per_second`, `generation_time_s`, and `time_to_first_token_s`.

## Example Response

The `x_i14_perf` object below is trimmed to three of its fields.

```json
{
  "id": "req_6e8933559cc247a6a38e46ef325a9f04",
  "object": "chat.completion",
  "created": 1791426845,
  "model": "i14-sugarglider-nemotron3-super-120b-v1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "\n\nA transformer model is a neural network architecture that uses self-attention mechanisms to process data in parallel, capturing long-range dependencies and achieving state-of-the-art performance in tasks like natural language processing and computer vision.",
        "reasoning_content": "Okay, the user wants a one-sentence explanation of a transformer model..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 48,
    "completion_tokens": 599,
    "total_tokens": 647,
    "completion_tokens_details": {
      "reasoning_tokens": 557
    }
  },
  "x_i14_perf": {
    "tokens_per_second": 36.244,
    "generation_time_s": 16.5268,
    "time_to_first_token_s": 0.1661
  }
}
```

## Streaming

Setting `"stream": true` in your request body switches the response from a single JSON object to a stream of [Server-Sent Events (SSE)](https://i14.ai/docs/api-usage/streaming/). Each event delivers a partial token delta as it is generated, letting you display results to users progressively without waiting for the full completion to finish. See the [Streaming guide](https://i14.ai/docs/api-usage/streaming/) for a complete walkthrough and code examples.
