pydantic-ai-gigachat
PydanticAI integration for GigaChat.
This package implements a native PydanticAI Model against GigaChat's own
/chat/completions API (not the OpenAI-compatibility shim), so all GigaChat
features — Russian profanity filter, repetition penalty, function calling,
streaming — are first-class.
Install
pip install pydantic-ai-gigachat
Requires Python 3.10+ and pydantic-ai-slim>=1.90.
Quick start
import asyncio
from pydantic_ai import Agent
from pydantic_ai_gigachat import GigaChatModel, GigaChatProvider
async def main():
provider = GigaChatProvider() # reads GIGACHAT_CREDENTIALS env
model = GigaChatModel("GigaChat", provider=provider)
agent = Agent(model, system_prompt="Отвечай коротко.")
result = await agent.run("Привет, как дела?")
print(result.output)
await provider.aclose()
asyncio.run(main())
Configuration
Credentials
Get your Authorization key from the
Sber developer cabinet (it's the
base64-encoded client_id:client_secret). Pass it explicitly or via env:
export GIGACHAT_CREDENTIALS="<authorization key>"
provider = GigaChatProvider(
authorization_key="...",
scope=GigaChatScope.PERS, # PERS / B2B / CORP
)
TLS certificates
GigaChat endpoints serve certificates signed by the Russian Trusted Root CA,
which is not in the standard certifi bundle. Three options:
-
Production — download the CA from
gu-st.ruand point the provider at it:export GIGACHAT_CA_BUNDLE_FILE=/path/to/russian_trusted_root_ca.cer
-
Append to certifi (one-shot, affects the whole venv):
curl -k "https://gu-st.ru/content/Other/doc/russian_trusted_root_ca.cer" \ >> $(python -m certifi)
-
Dev only —
GigaChatProvider(verify_ssl=False).
Features
| Feature | Status |
|---|---|
| Chat completions | ✅ |
| Streaming (SSE) | ✅ |
| Function calling | ✅ |
| OAuth2 token cache + refresh | ✅ |
| Custom CA bundle | ✅ |
Pre-flight token counting (Model.count_tokens) |
✅ |
Prompt cache reporting (cache_read_tokens) |
✅ |
| Embeddings | ⏭ planned |
/files (vision/RAG inputs) |
⏭ planned |
Available models
GigaChat, GigaChat-Pro, GigaChat-Max, GigaChat-2, GigaChat-2-Pro,
GigaChat-2-Max (and -preview early-access variants).
model = GigaChatModel("GigaChat-Max", provider=provider)
Settings passthrough
PydanticAI's ModelSettings map cleanly to GigaChat parameters:
temperature, top_p, max_tokens, n. GigaChat-specific knobs
(repetition_penalty, update_interval, profanity_check) work via
extra_body:
result = await agent.run(
"...",
model_settings={
"temperature": 0.3,
"max_tokens": 256,
"extra_body": {"profanity_check": True, "repetition_penalty": 1.1},
},
)
Examples
See examples/:
basic.py— minimal agenttools.py— function callingstreaming.py— streamed response
Development
python -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/pytest
License
MIT.
Metadata
Release files for pydantic-ai-gigachat 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydantic_ai_gigachat-0.1.0.tar.gz | 60.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_ai_gigachat-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 73.0 kB
Release files / pydantic_ai_gigachat-0.1.0.tar.gz
| Download URL | pydantic_ai_gigachat-0.1.0.tar.gz |
|---|---|
| Size | 60.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e2c56a9bc7b2bca87d69ec4f091d15866cefadf136b9f7a524023f089c24c5b
|
|
BLAKE2b-256 checksum How to use checksums |
e62b13d895ea8bd7a777b46d2763ca021ce6efbc55e6de66d176a3cc4a1b1569
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / pydantic_ai_gigachat-0.1.0-py3-none-any.whl
| Download URL | pydantic_ai_gigachat-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96821274a485fe16e145418c88ec21204d9f82fa4dc23dc64beb7997e61e2d11
|
|
BLAKE2b-256 checksum How to use checksums |
bf6d6fcf0fa9e7225aef4e78b1993e5098fd85f55f41816638643cb6f8982dee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|