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

# Chat Completions

> <ul><li>Create a model response from conversation history. Supports streaming and non-streaming responses.</li><li>Compatible with the OpenAI Chat Completions API.</li></ul>

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url 'https://api.elkapi.com/v1/chat/completions' \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-5.5",
    "messages": [
      {
        "role": "user",
        "content": "Hello, please introduce yourself"
      }
    ],
    "temperature": 1,
    "stream": false,
    "max_tokens": 1024,
    "response_format": "json"
  }'
  ```

  ```python Python theme={null} theme={null}
  import requests

  url = "https://api.elkapi.com/v1/chat/completions"
  headers = {
      "Authorization": "Bearer <token>"
  }
  headers["Content-Type"] = "application/json"
  payload = {
      "model": "gpt-5.5",
      "messages": [
          {
              "role": "user",
              "content": "Hello, please introduce yourself"
          }
      ],
      "temperature": 1,
      "stream": False,
      "max_tokens": 1024,
      "response_format": "json"
  }

  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null} theme={null}
  const url = "https://api.elkapi.com/v1/chat/completions";

  const headers = {
    "Authorization": "Bearer <token>"
  };
  headers["Content-Type"] = "application/json";
  const payload = {
    "model": "gpt-5.5",
    "messages": [
      {
        "role": "user",
        "content": "Hello, please introduce yourself"
      }
    ],
    "temperature": 1,
    "stream": false,
    "max_tokens": 1024,
    "response_format": "json"
  };

  const response = await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(payload)
  });

  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={null}
  {
    "id": "id",
    "object": "chat.completion",
    "created": 1,
    "model": "gpt-5.5",
    "choices": [
      {
        "index": 1,
        "message": {
          "role": "user",
          "content": "Hello, please introduce yourself",
          "name": "name",
          "tool_calls": [
            {
              "id": {},
              "type": {},
              "function": {}
            }
          ],
          "tool_call_id": "tool_call_id",
          "reasoning_content": "reasoning_content"
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 1,
      "completion_tokens": 1,
      "total_tokens": 1,
      "prompt_tokens_details": {
        "cached_tokens": 1,
        "text_tokens": 1,
        "audio_tokens": 1,
        "image_tokens": 1
      },
      "completion_tokens_details": {
        "text_tokens": 1,
        "audio_tokens": 1,
        "reasoning_tokens": 1
      }
    },
    "system_fingerprint": "system_fingerprint"
  }
  ```

  ```json 400 theme={null} theme={null}
  {
    "error": {
      "message": "message",
      "type": "type",
      "param": "param",
      "code": "code"
    }
  }
  ```

  ```json 429 theme={null} theme={null}
  {
    "error": {
      "message": "message",
      "type": "type",
      "param": "param",
      "code": "code"
    }
  }
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication.

  Add it to the request headers:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required default="gpt-5.5">
  Model ID

  Example: `gpt-5.5`
</ParamField>

<ParamField body="messages" type="array<object>" required>
  List of chat messages

  <ParamField body="messages.role" type="string" required>
    Message role

    Allowed values: `system`, `user`, `assistant`, `tool`, `developer`
  </ParamField>

  <ParamField body="messages.content" type="string or array<object>" required>
    Message content
  </ParamField>

  <ParamField body="messages.name" type="string">
    Sender name
  </ParamField>

  <ParamField body="messages.tool_calls" type="array<object>">
    <ParamField body="messages.tool_calls.id" type="string" />

    <ParamField body="messages.tool_calls.type" type="string">
      Example: `function`
    </ParamField>

    <ParamField body="messages.tool_calls.function" type="object">
      <ParamField body="messages.tool_calls.function.name" type="string" />

      <ParamField body="messages.tool_calls.function.arguments" type="string" />
    </ParamField>
  </ParamField>

  <ParamField body="messages.tool_call_id" type="string">
    Tool call ID (for tool role messages)
  </ParamField>

  <ParamField body="messages.reasoning_content" type="string">
    Reasoning content
  </ParamField>
</ParamField>

<ParamField body="temperature" type="number" default="1">
  Sampling temperature
</ParamField>

<ParamField body="top_p" type="number" default="1">
  Nucleus sampling parameter
</ParamField>

<ParamField body="n" type="integer" default="1">
  Generation count
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Whether to stream the response
</ParamField>

<ParamField body="stream_options" type="object">
  <ParamField body="stream_options.include_usage" type="boolean" />
</ParamField>

<ParamField body="stop" type="string or array<string>">
  Stop sequences
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum generated tokens
</ParamField>

<ParamField body="max_completion_tokens" type="integer">
  Maximum completion tokens
</ParamField>

<ParamField body="presence_penalty" type="number" default="0" />

<ParamField body="frequency_penalty" type="number" default="0" />

<ParamField body="logit_bias" type="object" />

<ParamField body="user" type="string" />

<ParamField body="tools" type="array<object>">
  <ParamField body="tools.type" type="string">
    Example: `function`
  </ParamField>

  <ParamField body="tools.function" type="object">
    <ParamField body="tools.function.name" type="string" />

    <ParamField body="tools.function.description" type="string" />

    <ParamField body="tools.function.parameters" type="object">
      Parameter definition in JSON Schema format
    </ParamField>
  </ParamField>
</ParamField>

<ParamField body="tool_choice" type="string or object">
  <ParamField body="tool_choice.type" type="string" />

  <ParamField body="tool_choice.function" type="object">
    <ParamField body="tool_choice.function.name" type="string" />
  </ParamField>
</ParamField>

<ParamField body="response_format" type="object">
  <ParamField body="response_format.type" type="string">
    Allowed values: `text`, `json_object`, `json_schema`
  </ParamField>

  <ParamField body="response_format.json_schema" type="object">
    JSON Schema definition
  </ParamField>
</ParamField>

<ParamField body="seed" type="integer" />

<ParamField body="reasoning_effort" type="string">
  Reasoning effort (for models that support reasoning)

  Allowed values: `low`, `medium`, `high`
</ParamField>

<ParamField body="modalities" type="array<string>" />

<ParamField body="audio" type="object">
  <ParamField body="audio.voice" type="string" />

  <ParamField body="audio.format" type="string" />
</ParamField>

## Response

<ResponseField name="id" type="string" />

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

<ResponseField name="created" type="integer" />

<ResponseField name="model" type="string" default="gpt-5.5">
  Example: `gpt-5.5`
</ResponseField>

<ResponseField name="choices" type="array<object>">
  <ResponseField name="choices.index" type="integer" />

  <ResponseField name="choices.message" type="object">
    <ResponseField name="choices.message.role" type="string" required>
      Message role

      Allowed values: `system`, `user`, `assistant`, `tool`, `developer`
    </ResponseField>

    <ResponseField name="choices.message.content" type="string or array<object>" required>
      Message content
    </ResponseField>

    <ResponseField name="choices.message.name" type="string">
      Sender name
    </ResponseField>

    <ResponseField name="choices.message.tool_calls" type="array<object>">
      <ResponseField name="choices.message.tool_calls.id" type="string" />

      <ResponseField name="choices.message.tool_calls.type" type="string">
        Example: `function`
      </ResponseField>

      <ResponseField name="choices.message.tool_calls.function" type="object" />
    </ResponseField>

    <ResponseField name="choices.message.tool_call_id" type="string">
      Tool call ID (for tool role messages)
    </ResponseField>

    <ResponseField name="choices.message.reasoning_content" type="string">
      Reasoning content
    </ResponseField>
  </ResponseField>

  <ResponseField name="choices.finish_reason" type="string">
    Allowed values: `stop`, `length`, `tool_calls`, `content_filter`
  </ResponseField>
</ResponseField>

<ResponseField name="usage" type="object">
  <ResponseField name="usage.prompt_tokens" type="integer">
    Prompt token count
  </ResponseField>

  <ResponseField name="usage.completion_tokens" type="integer">
    Completion token count
  </ResponseField>

  <ResponseField name="usage.total_tokens" type="integer">
    Total token count
  </ResponseField>

  <ResponseField name="usage.prompt_tokens_details" type="object">
    <ResponseField name="usage.prompt_tokens_details.cached_tokens" type="integer" />

    <ResponseField name="usage.prompt_tokens_details.text_tokens" type="integer" />

    <ResponseField name="usage.prompt_tokens_details.audio_tokens" type="integer" />

    <ResponseField name="usage.prompt_tokens_details.image_tokens" type="integer" />
  </ResponseField>

  <ResponseField name="usage.completion_tokens_details" type="object">
    <ResponseField name="usage.completion_tokens_details.text_tokens" type="integer" />

    <ResponseField name="usage.completion_tokens_details.audio_tokens" type="integer" />

    <ResponseField name="usage.completion_tokens_details.reasoning_tokens" type="integer" />
  </ResponseField>
</ResponseField>

<ResponseField name="system_fingerprint" type="string" />
