BerriAI/litellm · error · ValueError

Missing Mistral API Key - A call is being made to Mistral bu

Error message

Missing Mistral API Key - A call is being made to Mistral but no key is set either in the environment variables or via params

What it means

Raised by litellm's Mistral OCR transformer in validate_environment when no API key is available: neither an explicit api_key parameter nor the MISTRAL_OCR_API_KEY environment variable (fetched via get_secret_str) is set. It is a configuration error thrown before any network call is made.

Source

Thrown at litellm/llms/mistral/ocr/transformation.py:108

    def validate_environment(
        self,
        headers: dict,
        model: str,
        api_key: str | None = None,
        api_base: str | None = None,
        litellm_params: dict | None = None,
        **kwargs,
    ) -> dict:
        """
        Validate environment and return headers for Mistral OCR.
        """
        # Get API key from environment if not provided
        if api_key is None:
            api_key = get_secret_str(MISTRAL_OCR_API_KEY_ENV_VAR)

        if api_key is None:
            raise ValueError(
                "Missing Mistral API Key - A call is being made to Mistral but no key is set either in the environment variables or via params"
            )

        headers = {
            "Authorization": f"Bearer {api_key}",
            **headers,
        }

        # Don't set Content-Type for multipart/form-data - httpx will handle it

        return headers

    def get_complete_url(
        self,
        api_base: str | None,
        model: str,
        optional_params: dict,
        litellm_params: dict | None = None,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set MISTRAL_API_KEY (or the OCR-specific var litellm reads) in the process environment before importing/calling litellm.
  2. Or pass api_key explicitly: litellm.ocr(model=..., api_key=os.environ['MISTRAL_API_KEY']).
  3. In litellm proxy, add the key to the model's environment_variables in config.yaml.
  4. Verify with a quick check: python -c "import os; print(bool(os.getenv('MISTRAL_API_KEY')))".

Example fix

# before
result = litellm.ocr(model="mistral/mistral-ocr-latest", document=doc)

# after
result = litellm.ocr(
    model="mistral/mistral-ocr-latest",
    document=doc,
    api_key=os.environ["MISTRAL_API_KEY"],
)
Defensive patterns

Strategy: validation

Validate before calling

import os
if not (os.getenv("MISTRAL_API_KEY") or os.getenv("MISTRAL_OCR_API_KEY")):
    raise RuntimeError("Set MISTRAL_API_KEY before calling litellm.ocr with mistral models")

Try / catch

try:
    result = litellm.ocr(model="mistral/mistral-ocr-latest", document=doc)
except ValueError as e:
    if "Missing Mistral API Key" in str(e):
        raise RuntimeError("Configuration: MISTRAL_API_KEY missing") from e
    raise

Prevention

When it happens

Trigger: Calling litellm.ocr() with a mistral/* model without passing api_key and without MISTRAL_API_KEY/MISTRAL_OCR_API_KEY in the environment (or in a .env litellm is configured to read).

Common situations: New deployment where the env var was forgotten, CI workers that strip secret env vars, docker/k8s secret not mounted, or a typo in the variable name (e.g. MISTRAL_KEY).

Related errors


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