Skip to main content

Inference service interaction modes

Dedicated Inference 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 held open 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 dialog or message historyText generation models, multimodal models
Chat APIText generation in dialog mode — taking into account roles and message historyText generation models, multimodal models
Embeddings API

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

Embedding generation models
Rerank API

Evaluating relevance and sorting texts according to how well they match 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 blocks until a complete response from the model is received. 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; you can copy it in the control panel: in the top menu, click Products → Inference Services → on the inference service card, in the Inference Service Endpoint line, click ;

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

    • <model> — model name; you can check it in the control panel: in the top menu, click Products → Inference Services → inference service page → Service tab → Model line;

    • <prompt> — prompt, for example:

      Explain what a prompt is.
    • <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: in the top menu, click Products → Inference Services → inference service page → Service tab → Model line;

    • <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: in the top menu, click Products → Inference Services → inference service page → Service tab → Maximum context length line.

Send an asynchronous request

When sending an asynchronous request, the client code does not block, allowing other tasks to be performed while waiting for a response from the model. The client's connection with the server is held open 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; you can copy it in the control panel: in the top menu, click Products → Inference Services → on the inference service card, in the Inference Service Endpoint line, click ;

    • <api_key> control panel: in the top menu, click Products → Inference Services → inference service page → API Keys tab → in the API key line, click , and then ;

    • <model> — model name; you can check it in the control panel: in the top menu, click Products → Inference Services → inference service page → Service tab → Model line;

    • <prompt> — prompt, for example:

      Explain what a prompt is.
    • <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: in the top menu, click Products → Inference Services → inference service page → Service tab → Model line;

    • <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: in the top menu, click Products → Inference Services → inference service page → Service tab → Maximum context length line.