{"record":{"id":"bca8e1bf6eaa1020","repo":"BerriAI/litellm","slug":"missing-mistral-api-key-a-call-is-being-made-to","errorCode":null,"errorMessage":"Missing Mistral API Key - A call is being made to Mistral but no key is set either in the environment variables or via params","messagePattern":"Missing Mistral API Key - A call is being made to Mistral but no key is set either in the environment variables or via params","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/mistral/ocr/transformation.py","lineNumber":108,"sourceCode":"\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        api_base: str | None = None,\n        litellm_params: dict | None = None,\n        **kwargs,\n    ) -> dict:\n        \"\"\"\n        Validate environment and return headers for Mistral OCR.\n        \"\"\"\n        # Get API key from environment if not provided\n        if api_key is None:\n            api_key = get_secret_str(MISTRAL_OCR_API_KEY_ENV_VAR)\n\n        if api_key is None:\n            raise ValueError(\n                \"Missing Mistral API Key - A call is being made to Mistral but no key is set either in the environment variables or via params\"\n            )\n\n        headers = {\n            \"Authorization\": f\"Bearer {api_key}\",\n            **headers,\n        }\n\n        # Don't set Content-Type for multipart/form-data - httpx will handle it\n\n        return headers\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        model: str,\n        optional_params: dict,\n        litellm_params: dict | None = None,","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/mistral/ocr/transformation.py#L90-L126","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Set MISTRAL_API_KEY (or the OCR-specific var litellm reads) in the process environment before importing/calling litellm.","Or pass api_key explicitly: litellm.ocr(model=..., api_key=os.environ['MISTRAL_API_KEY']).","In litellm proxy, add the key to the model's environment_variables in config.yaml.","Verify with a quick check: python -c \"import os; print(bool(os.getenv('MISTRAL_API_KEY')))\"."],"exampleFix":"# before\nresult = litellm.ocr(model=\"mistral/mistral-ocr-latest\", document=doc)\n\n# after\nresult = litellm.ocr(\n    model=\"mistral/mistral-ocr-latest\",\n    document=doc,\n    api_key=os.environ[\"MISTRAL_API_KEY\"],\n)","handlingStrategy":"validation","validationCode":"import os\nif not (os.getenv(\"MISTRAL_API_KEY\") or os.getenv(\"MISTRAL_OCR_API_KEY\")):\n    raise RuntimeError(\"Set MISTRAL_API_KEY before calling litellm.ocr with mistral models\")","typeGuard":null,"tryCatchPattern":"try:\n    result = litellm.ocr(model=\"mistral/mistral-ocr-latest\", document=doc)\nexcept ValueError as e:\n    if \"Missing Mistral API Key\" in str(e):\n        raise RuntimeError(\"Configuration: MISTRAL_API_KEY missing\") from e\n    raise","preventionTips":["Fail fast at app startup on missing required provider env vars.","In litellm proxy, declare env vars per model in config.yaml.","Never assume a shared key covers chat and OCR products."],"tags":["mistral","ocr","api-key","configuration","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}