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

# Chat Completions

> OpenAI-compatible endpoint for LLM chat

<Tabs sync={false}>
  <Tab title="EN">
    ## POST /v1/chat/completions

    Standard OpenAI-compatible endpoint. Any library that supports OpenAI works without changes.

    **Base URL:** `https://api.lapathoniia.top`

    ### Parameters

    | Parameter | Type | Required | Description |
    | - | - | - | - |
    | `model` | string | ✅ | Model ID (see [Models](/models)) |
    | `messages` | array | ✅ | Array of messages |
    | `stream` | boolean | — | Streaming response (recommended) |
    | `temperature` | float | — | 0.0–2.0, default 0.15 |
    | `max_tokens` | integer | — | Maximum tokens in response |

    ### Examples

    <CodeGroup>
      ```python Streaming (recommended) theme={null}
      from openai import OpenAI

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

      stream = client.chat.completions.create(
          model="MamayLM-Gemma-3-27B-IT-v2.0",
          messages=[
              {"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "Tell me about Ukraine"},
          ],
          stream=True,
      )

      for chunk in stream:
          print(chunk.choices[0].delta.content or "", end="")
      ```

      ```python Without streaming theme={null}
      response = client.chat.completions.create(
          model="LapaLLM-Gemma-3-12B-v0.1.2-instruct",
          messages=[{"role": "user", "content": "Hello!"}],
      )
      print(response.choices[0].message.content)
      print(f"Tokens: {response.usage.total_tokens}")
      ```

      ```bash cURL theme={null}
      curl https://api.lapathoniia.top/v1/chat/completions \
        -H "Authorization: Bearer YOUR_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "MamayLM-Gemma-3-27B-IT-v2.0",
          "messages": [{"role": "user", "content": "What is AI?"}],
          "stream": false
        }'
      ```
    </CodeGroup>

    ### Response

    ```json theme={null}
    {
      "id": "chatcmpl-abc123",
      "object": "chat.completion",
      "model": "MamayLM-Gemma-3-27B-IT-v2.0",
      "choices": [{
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "Artificial intelligence (AI) is..."
        },
        "finish_reason": "stop"
      }],
      "usage": {
        "prompt_tokens": 12,
        "completion_tokens": 150,
        "total_tokens": 162
      }
    }
    ```

    ### Error Codes

    | Code | Cause |
    | - | - |
    | `401` | Invalid or missing API key |
    | `429` | Rate limit or budget exceeded |
    | `400` | Context window exceeded |
    | `503` | Model temporarily unavailable |
  </Tab>

  <Tab title="UA">
    ## POST /v1/chat/completions

    Стандартний OpenAI-сумісний ендпоінт. Будь-яка бібліотека, що підтримує OpenAI, працює без змін.

    **Base URL:** `https://api.lapathoniia.top`

    ### Parameters

    | Параметр | Тип | Обов’язковий | Опис |
    | - | - | - | - |
    | `model` | string | ✅ | ID моделі (див. [Моделі](/models)) |
    | `messages` | array | ✅ | Масив повідомлень |
    | `stream` | boolean | — | Streaming відповідь (рекомендовано) |
    | `temperature` | float | — | 0.0–2.0, за замовчуванням 0.15 |
    | `max_tokens` | integer | — | Максимум токенів у відповіді |

    ### Приклад

    ```python theme={null}
    from openai import OpenAI

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

    stream = client.chat.completions.create(
        model="MamayLM-Gemma-3-27B-IT-v2.0",
        messages=[{"role": "user", "content": "Розкажи про Україну"}],
        stream=True,
    )

    for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="")
    ```

    ### Коди помилок

    | Код | Причина |
    | - | - |
    | `401` | Невірний або відсутній API ключ |
    | `429` | Перевищено rate limit або бюджет |
    | `400` | Контекстне вікно перевищено |
    | `503` | Модель тимчасово недоступна |
  </Tab>
</Tabs>
