Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 98 additions & 6 deletions docs/my-website/docs/providers/gigachat.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ GigaChat is Sber AI's large language model, Russia's leading LLM provider.

:::warning

GigaChat API uses self-signed SSL certificates. You must pass `ssl_verify=False` in your requests.
GigaChat API commonly uses self-signed SSL certificates. By default, LiteLLM sets `ssl_verify=false` for GigaChat.
You can override per-request with `ssl_verify=True` or via env (`GIGACHAT_VERIFY_SSL_CERTS=true`).

:::

Expand All @@ -30,9 +31,11 @@ GigaChat API uses self-signed SSL certificates. You must pass `ssl_verify=False`
| Image Input | Yes (base64 and URL) - GigaChat-2-Max, GigaChat-2-Pro only |
| Embeddings | Yes |

## API Key
## Authentication

GigaChat uses OAuth authentication. Set your credentials as environment variables:
GigaChat supports two authentication methods:

### Method 1: OAuth 2.0

```python
import os
Expand All @@ -41,9 +44,33 @@ import os
os.environ['GIGACHAT_CREDENTIALS'] = "your-credentials-here"

# Optional: Set scope (default is GIGACHAT_API_PERS for personal use)
os.environ['GIGACHAT_SCOPE'] = "GIGACHAT_API_PERS" # or GIGACHAT_API_B2B for business
os.environ['GIGACHAT_SCOPE'] = "GIGACHAT_API_PERS" # or GIGACHAT_API_B2B, GIGACHAT_API_CORP
```

### Method 2: Basic Auth (user/password)

```python
import os

os.environ['GIGACHAT_USER'] = "your-username"
os.environ['GIGACHAT_PASSWORD'] = "your-password"
```

### Environment Variables

| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `GIGACHAT_CREDENTIALS` | Yes* | - | Base64-encoded OAuth credentials (client_id:client_secret) |
| `GIGACHAT_API_KEY` | Yes* | - | Alias for GIGACHAT_CREDENTIALS |
| `GIGACHAT_USER` | Yes* | - | Username for basic auth |
| `GIGACHAT_PASSWORD` | Yes* | - | Password for basic auth |
| `GIGACHAT_SCOPE` | No | `GIGACHAT_API_PERS` | API scope (GIGACHAT_API_PERS, GIGACHAT_API_B2B, GIGACHAT_API_CORP) |
| `GIGACHAT_AUTH_URL` | No | `https://ngw.devices.sberbank.ru:9443/api/v2/oauth` | OAuth endpoint URL |
| `GIGACHAT_API_BASE` | No | `https://gigachat.devices.sberbank.ru/api/v1` | API base URL |
| `GIGACHAT_VERIFY_SSL_CERTS` | No | `false` | Set `ssl_verify` for GigaChat requests|

\* Either `GIGACHAT_CREDENTIALS`/`GIGACHAT_API_KEY` OR `GIGACHAT_USER`+`GIGACHAT_PASSWORD` is required.

Get your credentials at: https://developers.sber.ru/studio/

## Sample Usage
Expand Down Expand Up @@ -188,9 +215,63 @@ response = embedding(
print(response)
```

## Sample Usage - PDF File Parsing

```python
import base64

from litellm import completion

def encode_file(file_path):
with open(file_path, "rb") as f:
return base64.b64encode(f.read()).decode("utf-8")


file_path = "path_to_your_file.pdf"

# Getting the base64 string
base64_pdf = encode_file(file_path)
response = completion(
model="gigachat/GigaChat-2-Max",
ssl_verify=False,
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Create a comprehensive summary of this pdf"},
{
"type": "file",
"file": {
"filename": "Day_2_v6.pdf",
"file_data": f"data:application/pdf;base64,{base64_pdf}"
}
},
],
}
],
)

print(response.choices[0].message.content)
```
## Usage with LiteLLM Proxy

### 1. Set GigaChat Models on config.yaml
### 1. Set Environment Variables

```bash
# Option 1: OAuth credentials
export GIGACHAT_CREDENTIALS="your-base64-credentials"

# Option 2: Basic auth
export GIGACHAT_USER="your-username"
export GIGACHAT_PASSWORD="your-password"

# Optional settings
export GIGACHAT_SCOPE="GIGACHAT_API_PERS" # API scope
export GIGACHAT_AUTH_URL="https://custom-auth-url" # Custom OAuth URL
export GIGACHAT_VERIFY_SSL_CERTS="false" # SSL verification (default: false)
```

### 2. Set GigaChat Models on config.yaml

```yaml
model_list:
Expand All @@ -211,7 +292,18 @@ model_list:
ssl_verify: false
```

### 2. Start Proxy
#### Using Basic Auth in config.yaml

```yaml
model_list:
- model_name: gigachat
litellm_params:
model: gigachat/GigaChat-2-Max
ssl_verify: false
# Credentials will be read from GIGACHAT_USER and GIGACHAT_PASSWORD env vars
```

### 3. Start Proxy

```bash
litellm --config config.yaml
Expand Down
1 change: 1 addition & 0 deletions docs/my-website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ const sidebars = {
"providers/fireworks_ai",
"providers/friendliai",
"providers/galadriel",
"providers/gigachat",
"providers/github",
"providers/github_copilot",
"providers/gradient_ai",
Expand Down
45 changes: 41 additions & 4 deletions litellm/llms/gigachat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,59 @@
GigaChat Provider for LiteLLM

GigaChat is Sber AI's large language model (Russia's leading LLM).

Supports:
- Chat completions (sync/async)
- Streaming (sync/async)
- Function calling / Tools
- Streaming (sync/async) with SSE parsing
- Function calling / Tools with automatic format conversion
- Structured output via JSON schema (emulated through function calls)
- Image input (base64 and URL)
- Image input (base64 and URL) with automatic file upload
- Embeddings
- OAuth 2.0 and basic auth (user/password)

GigaChat-specific features:
- repetition_penalty: Control repetition in generated text
- profanity_check: Enable content filtering
- flags: Feature flags for the API
- reasoning_effort: Reasoning effort level for reasoning models

API Documentation: https://developers.sber.ru/docs/ru/gigachat/api/overview
SDK: https://github.com/ai-forever/gigachat
"""

from .chat.transformation import GigaChatConfig, GigaChatError
from .authenticator import (
get_access_token,
get_access_token_async,
)
from .chat.transformation import GigaChatConfig
from .common_utils import (
GIGACHAT_AUTH_URL,
GIGACHAT_BASE_URL,
GIGACHAT_SCOPE,
TOKEN_EXPIRY_BUFFER_MS,
USER_AGENT,
GigaChatAuthError,
GigaChatError,
build_url,
)
from .embedding.transformation import GigaChatEmbeddingConfig

__all__ = [
# Config classes
"GigaChatConfig",
"GigaChatEmbeddingConfig",
# Constants
"GIGACHAT_BASE_URL",
"GIGACHAT_AUTH_URL",
"GIGACHAT_SCOPE",
"TOKEN_EXPIRY_BUFFER_MS",
"USER_AGENT",
# Exception classes
"GigaChatError",
"GigaChatAuthError",
# Auth functions
"get_access_token",
"get_access_token_async",
# Utils
"build_url",
]
Loading
Loading