GigaChat Python Library
raw JSON → 0.2.1 verified Mon Apr 27 auth: no python
Python library for GigaChat API by Sberbank. Current version 0.2.1, supports chat completions, embeddings, function calling, structured output (JSON schema), and streaming. Released regularly with minor updates.
pip install gigachat Common errors
error ImportError: cannot import name 'GigaChat' from 'gigachat' ↓
cause Older versions (pre 0.1.30) used a different import path.
fix
Upgrade gigachat: pip install --upgrade gigachat
error gigachat.exceptions.AuthenticationError: ... ↓
cause Invalid or missing credentials token.
fix
Ensure you provide a valid token as the 'credentials' parameter or set the GIGACHAT_TOKEN environment variable.
error AttributeError: 'Messages' object has no attribute 'dict' ↓
cause Pydantic V2 removed .dict() for models; use .model_dump() instead.
fix
Replace .dict() with .model_dump() for Pydantic models.
Warnings
breaking In v0.2.0, the synchronous client no longer uses 'requests' library; it uses 'httpx'. Code that relied on requests internals may break. ↓
fix Update to use httpx-based patterns. The client API remains the same.
breaking In v0.2.0, Pydantic V2 is used instead of V1. Models like Messages, ChatCompletion have changed their internal schema. Serialization with .dict() now returns a dict, not a Model instance. ↓
fix If you use .dict() or .json() on models, ensure compatibility with Pydantic V2. Use .model_dump() instead of .dict() if needed.
deprecated The 'user' parameter in GigaChat().chat() is deprecated in favor of passing user_id in the message dict. ↓
fix Use message format: {'role': 'user', 'content': '...', 'user_id': '...'}
gotcha The client defaults to verify_ssl_certs=False. For production, set verify_ssl_certs=True to avoid security warnings. ↓
fix Instantiate with GigaChat(credentials=..., verify_ssl_certs=True)
Imports
- GigaChat
from gigachat import GigaChat - Messages wrong
from gigachat import Messagescorrectfrom gigachat.models import Messages - ChatCompletion wrong
from gigachat import ChatCompletioncorrectfrom gigachat.models import ChatCompletion
Quickstart
from gigachat import GigaChat
import os
# Use environment variable for token (replace with your actual token)
token = os.environ.get('GIGACHAT_TOKEN', '')
with GigaChat(credentials=token, verify_ssl_certs=False) as giga:
response = giga.chat("Hello, how are you?")
print(response.choices[0].message.content)