Foundation Models Text Generation API, REST: TextGenerationAsync.Completion
- HTTP request
- Body parameters
- CompletionOptions
- ReasoningOptions
- Message
- ToolCallList
- ToolCall
- FunctionCall
- ToolResultList
- ToolResult
- FunctionResult
- Tool
- FunctionTool
- JsonSchema
- ToolChoice
- Response
- Status
- CompletionResponse
- Alternative
- Message
- ToolCallList
- ToolCall
- FunctionCall
- ToolResultList
- ToolResult
- FunctionResult
- ContentUsage
- CompletionTokensDetails
A method for generating text completions in asynchronous mode.
HTTP request
POST https://llm.api.cloud.yandex.net/foundationModels/v1/completionAsync
Body parameters
{
"modelUri": "string",
"completionOptions": {
"stream": "boolean",
"temperature": "number",
"maxTokens": "string",
"reasoningOptions": {
"mode": "string"
}
},
"messages": [
{
"role": "string",
// Includes only one of the fields `text`, `toolCallList`, `toolResultList`
"text": "string",
"toolCallList": {
"toolCalls": [
{
// Includes only one of the fields `functionCall`
"functionCall": {
"name": "string",
"arguments": "object"
}
// end of the list of possible fields
}
]
},
"toolResultList": {
"toolResults": [
{
// Includes only one of the fields `functionResult`
"functionResult": {
"name": "string",
// Includes only one of the fields `content`
"content": "string"
// end of the list of possible fields
}
// end of the list of possible fields
}
]
}
// end of the list of possible fields
}
],
"tools": [
{
// Includes only one of the fields `function`
"function": {
"name": "string",
"description": "string",
"parameters": "object",
"strict": "boolean"
}
// end of the list of possible fields
}
],
// Includes only one of the fields `jsonObject`, `jsonSchema`
"jsonObject": "boolean",
"jsonSchema": {
"schema": "object"
},
// end of the list of possible fields
"parallelToolCalls": "boolean",
"toolChoice": {
// Includes only one of the fields `mode`, `functionName`
"mode": "string",
"functionName": "string"
// end of the list of possible fields
}
}
Request for the service to generate text completion.
|
Field |
Description |
|
modelUri |
string The ID of the model to be used for completion generation. |
|
completionOptions |
Configuration options for completion generation. |
|
messages[] |
A list of messages representing the context for the completion model. |
|
tools[] |
List of tools that are available for the model to invoke during the completion generation. |
|
jsonObject |
boolean When set to true, the model will respond with a valid JSON object. Includes only one of the fields Specifies the format of the model's response. |
|
jsonSchema |
Enforces a specific JSON structure for the model's response based on a provided schema. Includes only one of the fields Specifies the format of the model's response. |
|
parallelToolCalls |
boolean Controls whether the model can generate multiple tool calls in a single response. Defaults to true. |
|
toolChoice |
Specifies how the model should select which tool (or tools) to use when generating a response. |
CompletionOptions
Defines the options for completion generation.
|
Field |
Description |
|
stream |
boolean Enables streaming of partially generated text. |
|
temperature |
number (double) Affects creativity and randomness of responses. Should be a double number between 0 (inclusive) and 1 (inclusive). |
|
maxTokens |
string (int64) The limit on the number of tokens used for single completion generation. |
|
reasoningOptions |
Configures reasoning capabilities for the model, allowing it to perform internal reasoning before responding. |
ReasoningOptions
Represents reasoning options that enable the model's ability to perform internal reasoning before generating a response.
|
Field |
Description |
|
mode |
enum (ReasoningMode) Specifies the reasoning mode to be used.
|
Message
A message object representing a wrapper over the inputs and outputs of the completion model.
|
Field |
Description |
|
role |
string The ID of the message sender. Supported roles:
|
|
text |
string Textual content of the message. Includes only one of the fields Message content. |
|
toolCallList |
List of tool calls made by the model as part of the response generation. Includes only one of the fields Message content. |
|
toolResultList |
List of tool results returned from external tools that were invoked by the model. Includes only one of the fields Message content. |
ToolCallList
Represents a list of tool calls.
|
Field |
Description |
|
toolCalls[] |
A list of tool calls to be executed. |
ToolCall
Represents a call to a tool.
|
Field |
Description |
|
functionCall |
Represents a call to a function. Includes only one of the fields |
FunctionCall
Represents the invocation of a function with specific arguments.
|
Field |
Description |
|
name |
string The name of the function being called. |
|
arguments |
object The structured arguments passed to the function. |
ToolResultList
Represents a list of tool results.
|
Field |
Description |
|
toolResults[] |
A list of tool results. |
ToolResult
Represents the result of a tool call.
|
Field |
Description |
|
functionResult |
Represents the result of a function call. Includes only one of the fields |
FunctionResult
Represents the result of a function call.
|
Field |
Description |
|
name |
string The name of the function that was executed. |
|
content |
string The result of the function call, represented as a string. Includes only one of the fields |
Tool
Represents a tool that can be invoked during completion generation.
|
Field |
Description |
|
function |
Represents a function that can be called. Includes only one of the fields |
FunctionTool
Represents a function tool that can be invoked during completion generation.
|
Field |
Description |
|
name |
string The name of the function. |
|
description |
string A description of the function's purpose or behavior. |
|
parameters |
object A JSON Schema that defines the expected parameters for the function. |
|
strict |
boolean Enforces strict adherence to the function schema, ensuring only defined parameters are used. |
JsonSchema
Represents the expected structure of the model's response using a JSON Schema.
|
Field |
Description |
|
schema |
object The JSON Schema that the model's output must conform to. |
ToolChoice
Specifies how the model should select which tool (or tools) to use when generating a response.
|
Field |
Description |
|
mode |
enum (ToolChoiceMode) Specifies the overall tool-calling mode. Includes only one of the fields
|
|
functionName |
string Forces the model to call a specific function. Includes only one of the fields |
Response
HTTP Code: 200 - OK
{
"id": "string",
"description": "string",
"createdAt": "string",
"createdBy": "string",
"modifiedAt": "string",
"done": "boolean",
"metadata": "object",
// Includes only one of the fields `error`, `response`
"error": {
"code": "integer",
"message": "string",
"details": [
"object"
]
},
"response": {
"alternatives": [
{
"message": {
"role": "string",
// Includes only one of the fields `text`, `toolCallList`, `toolResultList`
"text": "string",
"toolCallList": {
"toolCalls": [
{
// Includes only one of the fields `functionCall`
"functionCall": {
"name": "string",
"arguments": "object"
}
// end of the list of possible fields
}
]
},
"toolResultList": {
"toolResults": [
{
// Includes only one of the fields `functionResult`
"functionResult": {
"name": "string",
// Includes only one of the fields `content`
"content": "string"
// end of the list of possible fields
}
// end of the list of possible fields
}
]
}
// end of the list of possible fields
},
"status": "string"
}
],
"usage": {
"inputTextTokens": "string",
"completionTokens": "string",
"totalTokens": "string",
"completionTokensDetails": {
"reasoningTokens": "string"
}
},
"modelVersion": "string"
}
// end of the list of possible fields
}
An Operation resource. For more information, see Operation.
|
Field |
Description |
|
id |
string ID of the operation. |
|
description |
string Description of the operation. 0-256 characters long. |
|
createdAt |
string (date-time) Creation timestamp. String in RFC3339 text format. The range of possible values is from To work with values in this field, use the APIs described in the |
|
createdBy |
string ID of the user or service account who initiated the operation. |
|
modifiedAt |
string (date-time) The time when the Operation resource was last modified. String in RFC3339 text format. The range of possible values is from To work with values in this field, use the APIs described in the |
|
done |
boolean If the value is |
|
metadata |
object Service-specific metadata associated with the operation. |
|
error |
The error result of the operation in case of failure or cancellation. Includes only one of the fields The operation result. |
|
response |
The normal response of the operation in case of success. Includes only one of the fields The operation result. |
Status
The error result of the operation in case of failure or cancellation.
|
Field |
Description |
|
code |
integer (int32) Error code. An enum value of google.rpc.Code. |
|
message |
string An error message. |
|
details[] |
object A list of messages that carry the error details. |
CompletionResponse
Response containing generated text completions.
|
Field |
Description |
|
alternatives[] |
A list of generated completion alternatives. |
|
usage |
A set of statistics describing the number of content tokens used by the completion model. |
|
modelVersion |
string The model version changes with each new releases. |
Alternative
Represents a generated completion alternative, including its content and generation status.
|
Field |
Description |
|
message |
A message with the content of the alternative. |
|
status |
enum (AlternativeStatus) The generation status of the alternative.
|
Message
A message object representing a wrapper over the inputs and outputs of the completion model.
|
Field |
Description |
|
role |
string The ID of the message sender. Supported roles:
|
|
text |
string Textual content of the message. Includes only one of the fields Message content. |
|
toolCallList |
List of tool calls made by the model as part of the response generation. Includes only one of the fields Message content. |
|
toolResultList |
List of tool results returned from external tools that were invoked by the model. Includes only one of the fields Message content. |
ToolCallList
Represents a list of tool calls.
|
Field |
Description |
|
toolCalls[] |
A list of tool calls to be executed. |
ToolCall
Represents a call to a tool.
|
Field |
Description |
|
functionCall |
Represents a call to a function. Includes only one of the fields |
FunctionCall
Represents the invocation of a function with specific arguments.
|
Field |
Description |
|
name |
string The name of the function being called. |
|
arguments |
object The structured arguments passed to the function. |
ToolResultList
Represents a list of tool results.
|
Field |
Description |
|
toolResults[] |
A list of tool results. |
ToolResult
Represents the result of a tool call.
|
Field |
Description |
|
functionResult |
Represents the result of a function call. Includes only one of the fields |
FunctionResult
Represents the result of a function call.
|
Field |
Description |
|
name |
string The name of the function that was executed. |
|
content |
string The result of the function call, represented as a string. Includes only one of the fields |
ContentUsage
An object representing the number of content tokens used by the completion model.
|
Field |
Description |
|
inputTextTokens |
string (int64) The number of tokens in the textual part of the model input. |
|
completionTokens |
string (int64) The number of tokens in the generated completion. |
|
totalTokens |
string (int64) The total number of tokens, including all input tokens and all generated tokens. |
|
completionTokensDetails |
Provides additional information about how the completion tokens were utilized. |
CompletionTokensDetails
Provides additional information about how the completion tokens were utilized.
|
Field |
Description |
|
reasoningTokens |
string (int64) The number of tokens used specifically for internal reasoning performed by the model. |