Skip to main content

Inference service interaction modes

Foundation Models Catalog supports only 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 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 dialogue mode — taking into account roles and message historyText generation models, multimodal models
Embeddings API

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

Embedding generation models
Rerank API

Evaluating relevance and sorting texts by their degree of correspondence to a query. Used to improve response quality when using RAG

Text ranking models
Transcriptions APIConverting an audio file to textSpeech recognition models

Send a synchronous request

When sending a synchronous request, the client code is blocked until a full response is received from the model. 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> — inference service endpoint, which can be copied in the control panel: from the top menu, click ProductsInference Services → in the inference service card, in the Inference Service Endpoint row, click ;

    • <api_key> — API key, which can be copied 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, which can be viewed 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 will be. Recommended values are specified in the model description. You can find a link to the model description in the control panel: from the top menu, click ProductsInference Services → inference service page → Service tab → 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 → Service tab → Maximum Context Length.

Send an asynchronous request

When sending an asynchronous request, the client code is not blocked, allowing other tasks to be performed while waiting for a response from the model. The client connection to 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].text

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

    Specify:

    • <endpoint> — inference service endpoint, which can be copied in the control panel: from the top menu, click ProductsInference Services → in the inference service card, in the Inference Service Endpoint row, click ;

    • <api_key> — API key, which can be copied 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, which can be viewed 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 will be. Recommended values are specified in the model description. You can find a link to the model description in the control panel: from the top menu, click ProductsInference Services → inference service page → Service tab → 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 → Service tab → Maximum Context Length.