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>— the inference service endpoint; you can copy it in the control panel: from the top menu, click Products → Inference 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 Products → Inference 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 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. You can view the link to the model description in the control panel: from the top menu, click Products → Inference 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 Products → Inference 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.
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].message.contentasync 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 Products → Inference 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 Products → Inference 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 Products → Inference 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 Products → Inference 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 Products → Inference Services → inference service page → tab Service → row Maximum context length.
-