API Reference
This document contains a REST API reference for GigaChat.
Authorization
GigaChat API is available to legal entities and individual entrepreneurs after concluding an agreement. Payments are made on a postpaid basis.
GigaChat API requests are validated via OAuth 2.0 protocol using access tokens. The access token is sent in the Authorization
header:
curl https://gigachat.devices.sberbank.ru/api/v1/models \
-H 'Authorization: Bearer Token ***' \
For more information on using access tokens, see Authorization.
Description
The requests are processed under the following domain:
https://gigachat.devices.sberbank.ru/api/v1/
GET /models
Returns an array of objects containing the data for available models.
Request example:
curl https://gigachat.devices.sberbank.ru/api/v1/models \
-H 'Authorization: Bearer Token ***' \
Response:
- Пример
- Описание
{
"data": [
{
"id": "GigaChat:v1.2.19.2",
"object": "model",
"owned_by": "salutedevices"
}
],
"object": "list"
}
Models
Array [
]
data
object[]
Model name
Entity type in the reply. For example, a model.
Model owner
Entity type in the reply. For example, a list.
GET /models/{model}
Returns an object containing the description of the specified model.
Request example:
curl https://gigachat.devices.sberbank.ru/api/v1/models/GigaChat:v1.10.0 \
-H 'Authorization: Bearer Token ***' \
Request parameters:
ModelId
Model name
Response:
- Пример
- Описание
{
"id": "GigaChat:v1.2.19.2",
"object": "model",
"owned_by": "salutedevices"
}
Model
Model name
Entity type in the reply. For example, a model.
Model owner
POST /chat/completions
Returns a reply of the model considering the previously sent messages.
Request example:
curl https://gigachat.devices.sberbank.ru/api/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer Token ***' \
-d '{
"model": "GigaChat:latest",
"messages": [
{
"role": "user",
"content": "When will the AI take over the world?"
},
{
"role": "assistant",
"content": "So far, this has not been an inevitable menace. Although the AI is rapidly developing and is able to complete tricky tasks more and more effectively, it still has limited capabilities and cannot replace a human being in all areas. Also, there are AI-related ethic and legal constratins that are considered in its development and integration."
},
{
"role": "user",
"content": "Do you think we have a chance?"
}
],
"temperature": 0.7
}'
Request parameters:
Chat
Array [
]
- For values from 0 to 1, the model repeats the words that are already used
- Value 1 is a neutral value
- For values greater than 1, the model avoids repeating words
Name of the model you want to get a reply from.
To select the latest model, use GigaChat:latest
messages
object[]
required
Array of messages. Send the amount of messages that the service needs to base its replies on.
For more information, see Chat History
Возможные значения: [user
, assistant
, system
]
Message author role
Message text
Возможные значения: >= 0
и <= 2
По умолчанию: 0.87
Temperature of reply selection. The value ranges from 0 to 2. The greater the value, the more random reply the model gives.
We recommend not to use this parameter along with top_p
.
Возможные значения: >= 0
и <= 1
По умолчанию: 0.47
This parameter is an alternative to temperature
. It sets the possible array of tokens that is considered by the model.
For example, if the value is 0.1, the model considers only tokens within top 10% of the probability mass.
This parameter supports values from 0 to 1.
We recommend not to use this parameter along with temperature
.
Возможные значения: >= 1
и <= 4
По умолчанию: 1
The amount of reply options to generate for each message.
По умолчанию: false
Indicates that messages should be sent in parts as a stream.
The messages are sent via the SSE protocol.
A stream ends with the data: [DONE]
message.
For more information, see Streaming Response Messages.
По умолчанию: 512
The maximum ammount of tokens to use for replies.
По умолчанию: 1.07
The amount of repeating words:
По умолчанию: 0
Streaming mode parameter ("stream": "true"
).
This parameter sets the minimal interval between token sendings in seconds.
For example, if the value is set to 1, the messages are sent every second. This means that the size of each message is larger, because a larger amount of tokens is sent during one second.
Response:
- Пример
- Описание
{
"choices": [
{
"message": {
"role": "assistant",
"content": "Of course, mankind can always develop science and technologies to improve life quality and overcome challenges. It is important to continue researching the AI, find new methods of and approaches to its usage, and develop ethic principles and regulations that can help us make decisions based on our knowledge rather than emotions or prejudices."
},
"index": 0,
"finish_reason": "stop"
}
],
"created": 1678878333,
"model": "GigaChat:v1.2.19.2",
"usage": {
"prompt_tokens": 18,
"completion_tokens": 68,
"total_tokens": 86
},
"object": "chat.completion"
}
ChatCompletion
Array [
]
choices
object[]
The array of model replies
message
object
Generated message
Возможные значения: [user
, assistant
, system
]
Message author role
Message text
The index of the message in the array. Begins with 0.
The cause of finishing the hypothesis. For example, stop
indicates that the model has finished generating the hypothesis and given the full reply.Причина завершения гипотезы.
Creation date and time in the Unix time format
Name of the model that generated the reply
usage
object
Model usage data
The amount of tokens in each message
The amount of tokens generated by the model
The overall amount of tokens
Name of the requested mehod
POST /tokens/count
Returns an object with tokens quantity, counted by the set model in the input
array.
curl --location '{{baseUrl}}/tokens/count' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"model": "GigaChat",
"input": ["And the silken, sad, uncertain rustling of each purple curtain"]
}
'
Request parameters:
TokensCountBody
The Model which counts tokens.
An array of strings in which tokens will be counted.
Response:
- Пример
- Описание
[
{
"object": "tokens",
"tokens": 7,
"characters": 36
}
]
TokensCount
Array [
]
По умолчанию: tokens
Type of information contained in the object.
Tokens quantity in a string.
Characters quantity in a string.
Error Codes
Error Code | Description |
---|---|
401 | Unauthorized |
400 | Bad request format |
404 | No such Model |
422 | Validation error |
429 | Too many requests |
500 | Internal Server Error |