{"record":{"id":"5504064a8b9c7a4b","repo":"BerriAI/litellm","slug":"brave-api-key-is-not-set-set-brave-api-key-envi","errorCode":null,"errorMessage":"BRAVE_API_KEY is not set. Set `BRAVE_API_KEY` environment variable.","messagePattern":"BRAVE_API_KEY is not set\\. Set `BRAVE_API_KEY` environment variable\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/brave/search/transformation.py","lineNumber":128,"sourceCode":"        self,\n        headers: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n        **kwargs,\n    ) -> dict:\n        \"\"\"\n        Validate environment and return headers.\n        \"\"\"\n        api_key = self.resolve_server_api_key(\n            caller_api_key=api_key,\n            caller_api_base=api_base,\n            key_env_vars=(\"BRAVE_API_KEY\",),\n            base_env_var=\"BRAVE_API_BASE\",\n            default_api_base=self.BRAVE_API_BASE,\n        )\n\n        if not api_key:\n            raise ValueError(\"BRAVE_API_KEY is not set. Set `BRAVE_API_KEY` environment variable.\")\n\n        headers[\"X-Subscription-Token\"] = api_key\n        headers[\"Accept\"] = \"application/json\"\n        headers[\"Accept-Encoding\"] = \"gzip\"\n        headers[\"Content-Type\"] = \"application/json\"\n\n        return headers\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        optional_params: dict,\n        data: dict | list[dict] | None = None,\n        **kwargs,\n    ) -> str:\n        \"\"\"\n        Get complete URL for Search endpoint with query parameters.\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/brave/search/transformation.py#L110-L146","documentation":"Brave search transformation resolves the API key via resolve_server_api_key (caller api_key argument or BRAVE_API_KEY env var). If nothing resolves, it raises this plain ValueError before any HTTP call. Brave requires the X-Subscription-Token header, which cannot be built without the key.","triggerScenarios":"Invoking litellm's web search with the Brave provider without passing api_key and without BRAVE_API_KEY in the environment; typo'd env var name; key set in a different shell/process than the one running litellm (proxy, CI, docker).","commonSituations":"Deploying the LiteLLM proxy without forwarding BRAVE_API_KEY into the container; local shell exports not visible to a systemd service; rotating the key and forgetting to update the env; CI pipelines missing secrets.","solutions":["export BRAVE_API_KEY=<your key> in the process running LiteLLM.","Or pass the key explicitly via the api_key argument for the search call/config.","For the proxy, add BRAVE_API_KEY to the proxy environment (docker env, .env loaded by proxy).","Confirm with a quick check that the var is visible: python -c \"import os; print(bool(os.environ.get('BRAVE_API_KEY')))\"."],"exampleFix":"# before\n# BRAVE_API_KEY not set anywhere\nresults = litellm.web_search_provider(..., provider=\"brave\")\n\n# after\nos.environ[\"BRAVE_API_KEY\"] = \"BSA...\"\nresults = litellm.web_search_provider(..., provider=\"brave\")","handlingStrategy":"validation","validationCode":"import os\n\ndef brave_key_available() -> bool:\n    return bool(os.environ.get(\"BRAVE_API_KEY\"))","typeGuard":null,"tryCatchPattern":"try:\n    results = brave_search(query)\nexcept ValueError as e:\n    if \"BRAVE_API_KEY\" in str(e):\n        raise RuntimeError(\"Search unavailable: BRAVE_API_KEY not configured\") from e\n    raise","preventionTips":["Check the env var at app startup, not per request.","Inject the key via your deployment platform's secret mechanism so all processes see it."],"tags":["brave","web-search","api-key","env-var","authentication"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}