{"record":{"id":"20a6b0334ae22aaf","repo":"BerriAI/litellm","slug":"nvidia-nim-api-key-is-required-please-set-nvidia","errorCode":null,"errorMessage":"Nvidia NIM API key is required. Please set 'NVIDIA_NIM_API_KEY' in your environment","messagePattern":"Nvidia NIM API key is required\\. Please set 'NVIDIA_NIM_API_KEY' in your environment","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/nvidia_nim/rerank/transformation.py","lineNumber":163,"sourceCode":"        if non_default_params:\n            optional_nvidia_nim_rerank_params.update(non_default_params)\n        return dict(optional_nvidia_nim_rerank_params)\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        \"\"\"\n        Validate that the Nvidia NIM API key is present.\n        \"\"\"\n        if api_key is None:\n            api_key = get_secret_str(\"NVIDIA_NIM_API_KEY\") or litellm.api_key\n\n        if api_key is None:\n            raise ValueError(\"Nvidia NIM API key is required. Please set 'NVIDIA_NIM_API_KEY' in your environment\")\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 transform_rerank_request(\n        self,\n        model: str,\n        optional_rerank_params: dict,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/nvidia_nim/rerank/transformation.py#L145-L181","documentation":"Raised by litellm's Nvidia NIM rerank transformer in validate_environment when no API key can be resolved: api_key argument is None, NVIDIA_NIM_API_KEY env var is unset, and litellm.api_key is unset. Thrown before the rerank request is sent.","triggerScenarios":"Calling litellm.rerank() with model='nvidia_nim/...' without api_key, without NVIDIA_NIM_API_KEY in the environment, and without a global litellm.api_key — typical when targeting build.nvidia.com instead of a local NIM container.","commonSituations":"Switching from a local NIM deployment (no key needed) to NVIDIA's hosted endpoint (key required), missing secret in containers, or unset env var in notebooks.","solutions":["export NVIDIA_NIM_API_KEY=<key from build.nvidia.com> (nvapi-...).","Or pass api_key explicitly to litellm.rerank().","For local/self-hosted NIM, pass a dummy api_key if the container enforces the header.","In litellm proxy, add api_key to the nvidia_nim model's litellm_params."],"exampleFix":"# before\nlitellm.rerank(model=\"nvidia_nim/nv-rerankqa-mistral-4b-v3\", query=q, documents=docs)\n\n# after\nlitellm.rerank(\n    model=\"nvidia_nim/nv-rerankqa-mistral-4b-v3\",\n    query=q,\n    documents=docs,\n    api_key=os.environ[\"NVIDIA_NIM_API_KEY\"],\n)","handlingStrategy":"validation","validationCode":"import os\nif not (os.getenv(\"NVIDIA_NIM_API_KEY\") or litellm.api_key):\n    raise RuntimeError(\"NVIDIA_NIM_API_KEY required for hosted nvidia_nim rerank\")","typeGuard":null,"tryCatchPattern":"try:\n    litellm.rerank(model=\"nvidia_nim/nv-rerankqa-mistral-4b-v3\", query=q, documents=docs)\nexcept ValueError as e:\n    if \"NVIDIA_NIM_API_KEY\" in str(e):\n        raise RuntimeError(\"Config error: NVIDIA_NIM_API_KEY missing\") from e\n    raise","preventionTips":["Pass a dummy api_key for local NIM containers that require the header.","Keep hosted vs local NIM config in separate named profiles.","Preflight-check keys for every rerank provider you use."],"tags":["nvidia-nim","rerank","api-key","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}