BerriAI/litellm · error · GigaChatAuthError

GigaChat credentials not provided. Set GIGACHAT_CREDENTIALS…

Error message

GigaChat credentials not provided. Set GIGACHAT_CREDENTIALS or GIGACHAT_API_KEY environment variable.

What it means

GigaChatAuthError (a LiteLLM BaseLLMException with status_code 401) raised by the synchronous get_access_token when no credentials can be resolved. The resolver checks the explicit 'credentials' argument, then the GIGACHAT_CREDENTIALS and GIGACHAT_API_KEY secrets via LiteLLM's secret manager (environment or configured secret backend); all empty means OAuth cannot even start.

Solutions

  1. Set GIGACHAT_CREDENTIALS to the Base64 of client_id:client_secret obtained from the GigaChat developer portal: export GIGACHAT_CREDENTIALS=$(printf 'id:secret' | base64).
  2. Or set GIGACHAT_API_KEY if you use the simpler key form — the resolver accepts either.
  3. Or pass credentials per call: litellm.completion(model='gigachat/...', api_key=<base64 credentials>, ...) — the GigaChat chat transformer forwards api_key as credentials.
  4. In litellm proxy deployments, add the key to the environment/config of the proxy process and restart it.

Example fix

# before
import litellm
resp = litellm.completion(model="gigachat/GigaChat-2", messages=[{"role": "user", "content": "hi"}])
# GigaChatAuthError: credentials not provided

# after
import base64, os
os.environ["GIGACHAT_CREDENTIALS"] = base64.b64encode(
    b"<client_id>:<client_secret>"
).decode()
resp = litellm.completion(model="gigachat/GigaChat-2", messages=[{"role": "user", "content": "hi"}])
Defensive patterns

Strategy: validation

Validate before calling

import os


def gigachat_credentials_present() -> bool:
    """Check before the first litellm.completion('gigachat/...') call."""
    return bool(
        os.environ.get("GIGACHAT_CREDENTIALS") or os.environ.get("GIGACHAT_API_KEY")
    )


assert gigachat_credentials_present(), (
    "Set GIGACHAT_CREDENTIALS (base64 client_id:client_secret) or GIGACHAT_API_KEY"
)

Type guard

def is_gigachat_model(model: str) -> bool:
    return model.lower().startswith("gigachat/")

Try / catch

from litellm.llms.gigachat.authenticator import GigaChatAuthError

try:
    resp = litellm.completion(model="gigachat/GigaChat-2", messages=msgs)
except GigaChatAuthError as e:
    if e.status_code == 401 and "not provided" in str(e):
        raise RuntimeError("GigaChat credentials missing: set GIGACHAT_CREDENTIALS") from e
    raise

Prevention

When it happens

Trigger: litellm.completion(model='gigachat/...', messages=[...]) (or embedding/file helpers) on a machine where neither GIGACHAT_CREDENTIALS nor GIGACHAT_API_KEY is set and no api_key was passed — fresh checkout, new container, or CI runner without the secret.

Common situations: Forgot to export the env var; .env file not loaded in Docker/systemd/CI; secret named differently (e.g. GIGACHAT_TOKEN); deployed proxy missing the GIGACHAT_API_KEY environment value; assuming litellm.api_key covers GigaChat.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/31ca35a44cd45ae3. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/gigachat/authenticator.py:83

    auth_url: str | None = None,
) -> str:
    """
    Get valid access token, using cache if available.

    Args:
        credentials: Base64-encoded credentials (client_id:client_secret)
        scope: API scope (GIGACHAT_API_PERS, GIGACHAT_API_CORP, etc.)
        auth_url: OAuth endpoint URL

    Returns:
        Access token string

    Raises:
        GigaChatAuthError: If authentication fails
    """
    credentials = credentials or _get_credentials()
    if not credentials:
        raise GigaChatAuthError(
            status_code=401,
            message="GigaChat credentials not provided. Set GIGACHAT_CREDENTIALS or GIGACHAT_API_KEY environment variable.",
        )

    scope = scope or _get_scope()
    auth_url = auth_url or _get_auth_url()

    # Check cache
    cache_key: Final = f"gigachat_token:{credentials[:16]}"
    cached: Final = _token_cache.get_cache(cache_key)
    if cached:
        token, expires_at = cached
        # Check if token is still valid (with buffer)
        if time.time() * 1000 < expires_at - TOKEN_EXPIRY_BUFFER_MS:
            verbose_logger.debug("Using cached GigaChat access token")
            return token

    # Request new token

View on GitHub (pinned to 77b7c6c40c)