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.
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.
Completions API
Chat API
Embeddings API
Rerank API
Transcriptions API
curl
Python
Node.js
-
Open the CLI.
-
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, can be copied in the control panel: from the top menu, click Products → Inference Services → in the inference service card, in the Inference Service Endpoint row, click ; -
<api_key>— API key, can be copied in the control panel: from the top menu, click Products → Inference Services → inference service page → API Keys tab → in the API key row, click , and then ; -
<model>— model name, can be viewed in the control panel: 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: 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: in the top menu, click Products → Inference Services → inference service page → Service tab → 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.
Completions API
Chat API
Python
Node.js
-
Install the
openailibrary:pip install openai -
Send a request to the model:
import asynciofrom openai import AsyncOpenAIclient = 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].textasync def main():result = await get_completion()print(f"Response: {result}")Specify:
-
<endpoint>— inference service endpoint, can be copied in the control panel: from the top menu, click Products → Inference Services → in the inference service card, in the Inference Service Endpoint row, click ; -
<api_key>— API key, can be copied in the control panel: from the top menu, click Products → Inference Services → inference service page → API Keys tab → in the API key row, click , and then ; -
<model>— model name, can be viewed in the control panel: 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: 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: in the top menu, click Products → Inference Services → inference service page → Service tab → Maximum context length.
-