---
title: "Interaction modes with the inference service"
sidebar_label: "Interaction modes with the inference service"
sidebar_position: 1
description: "Supported interaction modes with the inference service, how to send requests to a model"
---

import CopyIcon from 'docs-kit/icons/copy';
import EyeIcon from 'docs-kit/icons/eye';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import {TabItemLabel} from 'docs-kit/components';
import { CustomTable } from 'docs-kit/components';
import Formbricks from '@theme/MDXComponents/Formbricks';

# Interaction modes with the inference service

The Foundation Models Catalog supports only the server-side synchronous mode. In this mode, the server processes the request and returns the result to the client within a single HTTP connection. The connection with the client is maintained until the response is fully generated.

On the client side, you can [send synchronous](#send-sync-request) and [asynchronous requests](#send-async-request).

Various [API types](#api-types) are available for working with models, depending on the task and model category.

## API types \{#api-types}

API types define the request data structure and response format. Available APIs depend on the model deployed in the inference service. Learn more about the API types in their official documentation.

<CustomTable>
  <table data-sticky>
    <thead>
      <tr>
        <th>API type</th><th>Description</th><th>Model category</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>[Completions API](https://developers.openai.com/api/docs/guides/completions)</td><td>Text generation based on a single prompt — without support for dialogue or message history</td><td>Text generation models, multimodal models</td>
      </tr>

      <tr>
        <td>[Chat API](https://developers.openai.com/api/reference/resources/chat)</td><td>Text generation in a dialogue mode — considering roles and message history</td><td>Text generation models, multimodal models</td>
      </tr>

      <tr>
        <td>[Embeddings API](https://developers.openai.com/api/docs/guides/embeddings)</td>

        <td>
          Converting text into numerical vectors — embeddings. Used for semantic search over data — for example, in vector databases
        </td>

        <td>Models for generating embeddings</td>
      </tr>

      <tr>
        <td>[Rerank API](https://jina.ai/reranker/)</td>

        <td>
          Evaluating relevance and sorting texts by how well they match the request. Used to improve response quality when using RAG
        </td>

        <td>Models for ranking texts</td>
      </tr>

      <tr>
        <td>[Transcriptions API](https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create)</td><td>Converting audio files to text</td><td>Models for speech recognition</td>
      </tr>
    </tbody>
  </table>
</CustomTable>

## Send a synchronous request \{#send-sync-request}

When sending a synchronous request, the client code is blocked until the model return a full response. This method is suitable for tasks that do not require parallel request processing.

<Tabs queryString="send-sync-request">
  <TabItem value="completions-api" default>
    <TabItemLabel>
      Completions API
    </TabItemLabel>

    <Tabs queryString="completions-api-sync">
      <TabItem value="curl" default>
        <TabItemLabel>
          curl
        </TabItemLabel>

        1. Open the CLI.

        2. Send a request to the model:

           ```bash
           curl <endpoint>/v1/completions \
           -H "Authorization: Bearer <api_key>" \
           -H "Content-Type: application/json" \
           -d '{
           "model": "<model>",
           "prompt": "<prompt>",
           "temperature": <temperature>,
           "max_tokens": <max_tokens>
           }'
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<prompt>` — prompt, for example:

             ```text
             Объясни, что такое промт.
             ```

           * `<temperature>` — generation temperature. The higher the value, the more diverse the responses. Recommended values are specified in the model description. A link to the model description can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>

      <TabItem value="python" default>
        <TabItemLabel>
          Python
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           pip install openai
           ```

        2. Send a request to the model:

           ```python
           from openai import OpenAI

           client = OpenAI(
               base_url="<endpoint>/v1",
               api_key="<api_key>"
           )

           def get_completion():
               response = client.completions.create(
                   model="<model>",
                   prompt="<prompt>",
                   temperature=<temperature>,
                   max_tokens=<max_tokens>
               )
               return response.choices[0].text

           result = get_completion()
           print(f"Response: {result}")
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<prompt>` — prompt, for example:

             ```text
             Объясни, что такое промт.
             ```

           * `<temperature>` — generation temperature. The higher the value, the more diverse the responses. Recommended values are specified in the model description. A link to the model description can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>

      <TabItem value="nodejs" default>
        <TabItemLabel>
          Node.js
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           npm install openai
           ```

        2. Send a request to the model:

           ```js
           import OpenAI from 'openai';

           const openai = new OpenAI({
             apiKey: '<api_key>',
             baseURL: '<endpoint>/v1',
           });

           async function getCompletion() {
             const response = await openai.completions.create({
               model: "<model>",
               prompt: "<prompt>",
               temperature: <temperature>,
               max_tokens: <max_tokens>,
             });

             console.log(response.choices[0].text);
           }

           getCompletion();
           ```

           Specify:

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<prompt>` — prompt, for example:

             ```text
             Объясни, что такое промт.
             ```

           * `<temperature>` — generation temperature. The higher the value, the more diverse the responses. Recommended values are specified in the model description. A link to the model description can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="chat-api">
    <TabItemLabel>
      Chat API
    </TabItemLabel>

    <Tabs queryString="chat-api-sync">
      <TabItem value="curl" default>
        <TabItemLabel>
          curl
        </TabItemLabel>

        1. Open the CLI.

        2. Send a request to the model:

           ```bash
           curl <endpoint>/v1/chat/completions \
           -H "Authorization: Bearer <api_key>" \
           -H "Content-Type: application/json" \
           -d '{
               "model": "<model>",
               "messages": [
                 {
                 "role": "<role_1>",
                 "content": "<prompt_1>"
                 },
                 {
                 "role": "<role_2>",
                 "content": "<prompt_2>"
                 }
               ]
           }'
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<role_1>` — role of the message sender, for example `developer`;

           * `<prompt_1>` — prompt for the specified role, for example:

             ```text
             Ты виртуальный ассистент-помощник.
             ```

           * `<role_2>` — role of the message sender, for example `user`;

           * `<prompt_2>` — prompt for the specified role, for example:

             ```text
             Объясни, что такое промт.
             ```
      </TabItem>

      <TabItem value="python" default>
        <TabItemLabel>
          Python
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           pip install openai
           ```

        2. Send a request to the model:

           ```python
           from openai import OpenAI

           client = OpenAI(
               base_url="<endpoint>/v1",
               api_key="<api_key>"
           )

           def get_chat_completion():
               response = client.chat.completions.create(
                   model="<model>",
                   messages=[
                       {"role": "<role_1>", "content": "<prompt_1>"},
                       {"role": "<role_2>", "content": "<prompt_2>"},
                   ],
                   max_tokens=<max_tokens>
               )
               return response.choices[0].message.content

           result = get_chat_completion()
           print(f"Response: {result}")
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<role_1>` — role of the message sender, for example `developer`;

           * `<prompt_1>` — prompt for the specified role, for example:

             ```text
             Ты виртуальный ассистент-помощник.
             ```

           * `<role_2>` — role of the message sender, for example `user`;

           * `<prompt_2>` — prompt for the specified role, for example:

             ```text
             Объясни, что такое промт.
             ```

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>

      <TabItem value="nodejs" default>
        <TabItemLabel>
          Node.js
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           npm install openai
           ```

        2. Send a request to the model:

           ```js
           import OpenAI from 'openai';

           const openai = new OpenAI({
             apiKey: '<api_key>',
             baseURL: '<endpoint>/v1',
           });

           async function getChatCompletion() {
             const response = await openai.chat.completions.create({
               model: "<model>",
               messages: [
                 { role: "<role_1>", content: "<prompt_1>" },
                 { role: "<role_2>", content: "<prompt_2>" },
               ],
             });

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

           getChatCompletion();
           ```

           Specify:

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<role_1>` — role of the message sender, for example `developer`;

           * `<prompt_1>` — prompt for the specified role, for example:

             ```text
             Ты виртуальный ассистент-помощник.
             ```

           * `<role_2>` — role of the message sender, for example `user`;

           * `<prompt_2>` — prompt for the specified role, for example:

             ```text
             Объясни, что такое промт.
             ```
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="embeddings-api">
    <TabItemLabel>
      Embeddings API
    </TabItemLabel>

    <Tabs queryString="embeddings-api-sync">
      <TabItem value="curl" default>
        <TabItemLabel>
          curl
        </TabItemLabel>

        1. Open the CLI.

        2. Send a request to the model:

           ```bash
           curl <endpoint>/v1/embeddings \
           -H "Authorization: Bearer <api_key>" \
           -H "Content-Type: application/json" \
           -d '{
               "model": "<model>",
               "encoding_format": "<encoding_format>",
               "input": [
                   "<input_text>"
                   ]
           }'
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<encoding_format>` — output encoding format, for example `float`;

           * `<input_text>` — text to be converted into a vector, for example:

             ```text
             Что такое машинное обучение?
             ```
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="rerank-api">
    <TabItemLabel>
      Rerank API
    </TabItemLabel>

    <Tabs queryString="rerank-api-sync">
      <TabItem value="curl" default>
        <TabItemLabel>
          curl
        </TabItemLabel>

        1. Open the CLI.

        2. Send a request to the model:

           ```bash
           curl <endpoint>/v1/rerank \
           -H "Authorization: Bearer <api_key>" \
           -H "Content-Type: application/json" \
           -d '{
             "model": "<model>",
             "query": "<query>",
             "documents": [
               "<document_1>",
               "<document_2>"
             ]
           }'
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<query>` — search query used to evaluate text relevance, for example:

             ```text
             Назови столицу Франции.
             ```

           * `<document_1>`, `<document_2>` — texts of documents to be ranked. Each document is passed as a string. For example, for `<document_1>`:

             ```text
             Париж — столица Франции.
             ```
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="transcriptions-api">
    <TabItemLabel>
      Transcriptions API
    </TabItemLabel>

    <Tabs queryString="transcriptions-api-sync">
      <TabItem value="curl" default>
        <TabItemLabel>
          curl
        </TabItemLabel>

        1. Open the CLI.

        2. Send a request to the model:

           ```bash
           curl <endpoint>/v1/audio/transcriptions \
           -H "Authorization: Bearer <api_key>" \
           -F "file=@<audio_file_path>" \
           -F "model=<model>" \
           -F "language=<language>" \
           -F "response_format=<response_format>"
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<audio_file_path>` — path to the audio file;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<language>` — language of the audio recording, for example `en`, `ru`;

           * `<response_format>` — response output format, for example `verbose_json`, `json`.
      </TabItem>
    </Tabs>
  </TabItem>
</Tabs>

## Send an asynchronous request \{#send-async-request}

When sending an asynchronous request, the client code is not blocked, which allows you to perform other tasks while waiting for the response from the model. The connection between the client and the server is maintained until a full response is received.

<Tabs queryString="send-async-request">
  <TabItem value="completions-api" default>
    <TabItemLabel>
      Completions API
    </TabItemLabel>

    <Tabs queryString="completions-api-async">
      <TabItem value="python" default>
        <TabItemLabel>
          Python
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           pip install openai
           ```

        2. Send a request to the model:

           ```python
           import asyncio
           from openai import AsyncOpenAI

           client = AsyncOpenAI(
               base_url="<endpoint>/v1",
               api_key="<api_key>"
           )

           async def get_completion():
               response = await client.completions.create(
                   model="<model>",
                   prompt="<prompt>",
                   temperature=<temperature>,
                   max_tokens=<max_tokens>
               )
               return response.choices[0].text

           async def main():
               result = await get_completion()
               print(f"Response: {result}")
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<prompt>` — prompt, for example:

             ```
             Объясни, что такое промт.
             ```

           * `<temperature>` — generation temperature. The higher the value, the more diverse the responses. Recommended values are specified in the model description. A link to the model description can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>

      <TabItem value="nodejs" default>
        <TabItemLabel>
          Node.js
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           npm install openai
           ```

        2. Send a request to the model:

           ```js
           import OpenAI from 'openai';

           const openai = new OpenAI({
             apiKey: '<api_key>',
             baseURL: '<endpoint>/v1',
           });

           async function getCompletion() {
             const response = await openai.completions.create({
               model: "<model>",
               prompt: "<prompt>",
               temperature: <temperature>,
               max_tokens: <max_tokens>,
             });

             console.log(response.choices[0].text);
           }

           getCompletion();
           ```

           Specify:

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<prompt>` — prompt, for example:

             ```
             Объясни, что такое промт.
             ```

           * `<temperature>` — generation temperature. The higher the value, the more diverse the responses. Recommended values are specified in the model description. A link to the model description can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="chat-api">
    <TabItemLabel>
      Chat API
    </TabItemLabel>

    <Tabs queryString="chat-api-async">
      <TabItem value="python" default>
        <TabItemLabel>
          Python
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           pip install openai
           ```

        2. Send a request to the model:

           ```python
           import asyncio
           from openai import AsyncOpenAI

           client = AsyncOpenAI(
               base_url="<endpoint>/v1",
               api_key="<api_key>"
           )

           async def get_chat_completion():
               response = await client.chat.completions.create(
                   model="<model>",
                   messages=[
                       {"role": "<role_1>", "content": "<prompt_1>"},
                       {"role": "<role_2>", "content": "<prompt_2>"},
                   ],
                   max_tokens=<max_tokens>
               )
               return response.choices[0].message.content

           async def main():
               result = await get_chat_completion()
               print(f"Response: {result}")
           ```

           Specify:

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<role_1>` — role of the message sender, for example `developer`;

           * `<prompt_1>` — prompt for the specified role, for example:

             ```
             Ты виртуальный ассистент-помощник.
             ```

           * `<role_2>` — role of the message sender, for example `user`;

           * `<prompt_2>` — prompt for the specified role, for example:

             ```
             Объясни, что такое промт.
             ```

           * `<max_tokens>` — maximum number of tokens in the model response. Cannot exceed the maximum context length. The maximum context length can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Maximum context length**.
      </TabItem>

      <TabItem value="nodejs" default>
        <TabItemLabel>
          Node.js
        </TabItemLabel>

        1. Install the `openai` library:

           ```bash
           npm install openai
           ```

        2. Send a request to the model:

           ```js
           import OpenAI from 'openai';

           const openai = new OpenAI({
             apiKey: '<api_key>',
             baseURL: '<endpoint>/v1',
           });

           async function getChatCompletion() {
             const response = await openai.chat.completions.create({
               model: "<model>",
               messages: [
                 { role: "<role_1>", content: "<prompt_1>" },
                 { role: "<role_2>", content: "<prompt_2>" },
               ],
             });

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

           getChatCompletion();
           ```

           Specify:

           * `<api_key>` — API key, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → inference service page → **API Keys** tab → in the API key row, click <EyeIcon />, and then <CopyIcon />;

           * `<endpoint>` — inference service endpoint, can be copied in the [control panel](https://my.selectel.ru/ml/default/inference-services/): from the top menu, click **Products** → **Inference Services** → in the inference service card, in the **Inference Service Endpoint** row, click <CopyIcon />;

           * `<model>` — model name, can be viewed in the [control panel](https://my.selectel.ru/ml/default/inference-services/): in the top menu, click **Products** → **Inference Services** → inference service page → **Service** tab → **Model**;

           * `<role_1>` — role of the message sender, for example `developer`;

           * `<prompt_1>` — prompt for the specified role, for example:

             ```
             Ты виртуальный ассистент-помощник.
             ```

           * `<role_2>` — role of the message sender, for example `user`;

           * `<prompt_2>` — prompt for the specified role, for example:

             ```
             Объясни, что такое промт.
             ```
      </TabItem>
    </Tabs>
  </TabItem>
</Tabs>

<Formbricks />
