Skip to main content

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 and asynchronous requests.

Various API types are available for working with models, depending on the task and model category.

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.

API typeDescriptionModel category
Completions APIText generation based on a single prompt — without support for dialogue or message historyText generation models, multimodal models
Chat APIText generation in a dialogue mode — considering roles and message historyText generation models, multimodal models
Embeddings API

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

Models for generating embeddings
Rerank API

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

Models for ranking texts
Transcriptions APIConverting audio files to textModels for speech recognition

Send a synchronous 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.

  1. Open the CLI.

  2. Send a request to the model:

    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> — the inference service endpoint; you can copy it in the control panel: from the top menu, click ProductsInference Services → inference service page → Quick Start tab → in the Endpoint block, click ;

    • <api_key> — API key; you can copy it in the control panel: from the top menu, click ProductsInference Services → inference service page → API Keys tab → in the API key row, click , and then ;

    • <model> — model name; you can view it in the control panel: from the top menu, click ProductsInference 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. You can view the link to the model description in the control panel: from the top menu, click ProductsInference Services → inference service page → tab Service → row Model;

    • <max_tokens> — maximum number of tokens in the model response. Cannot exceed the maximum context length. You can view the maximum context length in the control panel: from the top menu, click ProductsInference Services → inference service page → tab Service → row Maximum context length.

Send an asynchronous 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.

  1. Install the openai library:

    pip install openai
  2. Send a request to the model:

    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].message.content

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

    Specify:

    • <endpoint> — the inference service endpoint; you can copy it in the control panel: from the top menu, click ProductsInference Services → inference service page → Quick Start tab → in the Endpoint block, click ;

    • <api_key> — API key; you can copy it in the control panel: from the top menu, click ProductsInference Services → inference service page → API Keys tab → in the API key row, click , and then ;

    • <model> — model name; you can view it in the control panel: from the top menu, click ProductsInference Services → inference service page → tab Service → row Model;

    • <prompt> — prompt, for example</g:

      Объясни, что такое промт.
    • <temperature> — generation temperature. The higher the value, the more diverse the responses. Recommended values are specified in the model description. You can view the link to the model description in the control panel: from the top menu, click ProductsInference Services → inference service page → tab Service → row Model;

    • <max_tokens> — maximum number of tokens in the model response. Cannot exceed the maximum context length. You can view the maximum context length in the control panel: from the top menu, click ProductsInference Services → inference service page → tab Service → row Maximum context length.