GigaChat API Integration (Sber)
GigaChat is an LLM from Sberbank through SberCloud. Like YandexGPT — Russian jurisdiction for data processing, important for financial institutions, government structures and companies with data localization requirements under 152-FZ. GigaChat integrates with Sber ecosystem: SberDevices, SberCloud, GigaChain (LangChain fork).
Getting Access
# 1. Register on developers.sber.ru
# 2. Create project and get client_id / client_secret
# 3. OAuth 2.0 authorization to get access_token
import requests
import base64
import uuid
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
SCOPE = "GIGACHAT_API_PERS" # For individuals
# GIGACHAT_API_B2B for business
# GIGACHAT_API_CORP for corporate
def get_access_token() -> str:
credentials = base64.b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode()).decode()
response = requests.post(
"https://ngw.devices.sberbank.ru:9443/api/v2/oauth",
headers={
"Authorization": f"Basic {credentials}",
"RqUID": str(uuid.uuid4()),
"Content-Type": "application/x-www-form-urlencoded",
},
data={"scope": SCOPE},
verify=False, # Sber self-signed certificate
)
return response.json()["access_token"]
Basic Requests
def gigachat_chat(prompt: str, access_token: str) -> str:
response = requests.post(
"https://gigachat.devices.sberbank.ru/api/v1/chat/completions",
headers={"Authorization": f"Bearer {access_token}"},
json={
"model": "GigaChat",
"messages": [{"role": "user", "content": prompt}],
"temperature": 0.1,
"max_tokens": 1024,
},
verify=False,
)
return response.json()["choices"][0]["message"]["content"]
# With token caching
from datetime import datetime, timedelta
class GigaChatClient:
def __init__(self, client_id: str, client_secret: str):
self.client_id = client_id
self.client_secret = client_secret
self._token = None
self._token_expires = None
def _ensure_token(self):
if not self._token or datetime.now() >= self._token_expires:
self._token = get_access_token()
self._token_expires = datetime.now() + timedelta(minutes=25) # Token lives 30 min
def chat(self, messages: list[dict], model: str = "GigaChat") -> str:
self._ensure_token()
response = requests.post(
"https://gigachat.devices.sberbank.ru/api/v1/chat/completions",
headers={"Authorization": f"Bearer {self._token}"},
json={"model": model, "messages": messages, "temperature": 0.1},
verify=False,
)
return response.json()["choices"][0]["message"]["content"]
GigaChain — LangChain for GigaChat
from langchain_community.chat_models import GigaChat
from langchain_core.messages import HumanMessage, SystemMessage
chat = GigaChat(
credentials="Base64(client_id:client_secret)",
scope="GIGACHAT_API_PERS",
model="GigaChat",
verify_ssl_certs=False,
streaming=False,
)
response = chat.invoke([
SystemMessage(content="You are a financial consultant"),
HumanMessage(content="Explain the key rate of the Central Bank of Russia"),
])
print(response.content)
GigaChat Models
| Model | Description |
|---|---|
| GigaChat | Base model |
| GigaChat-Plus | Enhanced version |
| GigaChat-Pro | Maximum quality |
| GigaChat-Max | Flagship |
Use Case
Bank contact center: automatic answers to customer questions about products. GigaChat chosen due to regulatory requirements for localization of bank customer data. Integration with internal CRM via REST API.
Timeline
- Access + basic integration: 2–3 days
- GigaChain/LangChain integration: 1 week
- Production with token refresh and retry: +2–3 days







