BerriAI/litellm · error · ValueError

Master key must be 32 bytes for AES-256-GCM

Error message

Master key must be 32 bytes for AES-256-GCM

What it means

Error "Master key must be 32 bytes for AES-256-GCM" thrown in BerriAI/litellm.

Source

Thrown at litellm/litellm_core_utils/app_crypto.py:12

import base64
import json
import os
from typing import Final

from cryptography.hazmat.primitives.ciphers.aead import AESGCM


class AppCrypto:
    def __init__(self, master_key: bytes):
        if len(master_key) != 32:
            raise ValueError("Master key must be 32 bytes for AES-256-GCM")
        self.key = master_key

    def encrypt_json(self, data: dict, aad: bytes | None = None) -> dict:
        aes: Final = AESGCM(self.key)
        nonce: Final = os.urandom(12)
        plaintext: Final = json.dumps(data).encode("utf-8")
        ct: Final = aes.encrypt(nonce, plaintext, aad)
        ciphertext, tag = ct[:-16], ct[-16:]
        return {
            "nonce": base64.b64encode(nonce).decode(),
            "ciphertext": base64.b64encode(ciphertext).decode(),
            "tag": base64.b64encode(tag).decode(),
        }

    def decrypt_json(self, enc: dict, aad: bytes | None = None) -> dict:
        aes: Final = AESGCM(self.key)
        nonce: Final = base64.b64decode(enc["nonce"])
        ct: Final = base64.b64decode(enc["ciphertext"])

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Provide a 32-byte master key for AES-256-GCM.

When it happens

Trigger: Thrown at litellm/litellm_core_utils/app_crypto.py:12 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/47dea8f07b9f315a. Report an issue: GitHub.