{"record":{"id":"3f7a64e5aee8e17b","repo":"BerriAI/litellm","slug":"deepinfra-api-key-is-required-please-set-deepinf","errorCode":null,"errorMessage":"Deepinfra API key is required. Please set 'DEEPINFRA_API_KEY' environment variable","messagePattern":"Deepinfra API key is required\\. Please set 'DEEPINFRA_API_KEY' environment variable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"litellm/llms/deepinfra/rerank/transformation.py","lineNumber":75,"sourceCode":"\n        # Remove any trailing slashes for consistency, then add one\n        api_base_clean = api_base_clean.rstrip(\"/\") + \"/\"\n\n        # Compose the full endpoint\n        return f\"{api_base_clean}inference/{model}\"\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        optional_params: dict | None = None,\n    ) -> dict:\n        if api_key is None:\n            api_key = get_secret_str(\"DEEPINFRA_API_KEY\")\n\n        if api_key is None:\n            raise ValueError(\"Deepinfra API key is required. Please set 'DEEPINFRA_API_KEY' environment variable\")\n\n        default_headers: Final = {\n            \"Authorization\": f\"Bearer {api_key}\",\n            \"accept\": \"application/json\",\n            \"content-type\": \"application/json\",\n        }\n\n        # If 'Authorization' is provided in headers, it overrides the default.\n        if \"Authorization\" in headers:\n            default_headers[\"Authorization\"] = headers[\"Authorization\"]\n\n        # Merge other headers, overriding any default ones except Authorization\n        return {**default_headers, **headers}\n\n    def map_cohere_rerank_params(\n        self,\n        non_default_params: dict,\n        model: str,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/deepinfra/rerank/transformation.py#L57-L93","documentation":"Credential guard in the DeepInfra rerank config: api_key was None and the DEEPINFRA_API_KEY environment secret is unset, so the rerank request would be unauthorized and is rejected before dispatch.","triggerScenarios":"Thrown at litellm/llms/deepinfra/rerank/transformation.py:75 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the DEEPINFRA_API_KEY environment variable before making the call, e.g. export DEEPINFRA_API_KEY=<your-key>.","Alternatively pass the credential directly via the api_key parameter in the litellm call."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}