{"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":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/brave/search/transformation.py#L110-L146","documentation":"For the Brave search provider, validate_environment resolves the API key via resolve_server_api_key (caller api_key, then BRAVE_API_KEY env / server-side config). If resolution returns nothing, this ValueError is raised before any request is sent. It is purely a configuration error, not a Brave-side rejection.","triggerScenarios":"Invoking litellm's Brave search/web search with no api_key argument while BRAVE_API_KEY is unset in both the caller's environment and the litellm proxy server's secret store.","commonSituations":"New deployments missing the env var; litellm proxy users who set the key on the client but the proxy requires it server-side; .env not loaded in serverless/CI; key configured under a different provider's name.","solutions":["export BRAVE_API_KEY=<key> (get one from the Brave Search API dashboard) in the process running litellm.","Or pass api_key explicitly in the call.","On litellm proxy, set it in the environment of the proxy process or its env_config, then restart.","Verify: echo ${BRAVE_API_KEY:+set} inside the same runtime."],"exampleFix":"# before\nlitellm.web_search(...)  # or proxy config without the key\n\n# after\nexport BRAVE_API_KEY=BSAxxx\n# or\nresponse = litellm.completion(..., web_search_options=...)  # with BRAVE_API_KEY exported","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"BRAVE_API_KEY\"):\n    raise RuntimeError(\"BRAVE_API_KEY must be set before enabling Brave search\")","typeGuard":null,"tryCatchPattern":"try:\n    result = brave_search_call(...)\nexcept ValueError as e:\n    if \"BRAVE_API_KEY is not set\" in str(e):\n        raise SystemExit(\"Configuration error: set BRAVE_API_KEY\") from e  # fail fast, no retry\n    raise","preventionTips":["Add a boot-time check for BRAVE_API_KEY in services using Brave search.","Store provider keys in a secrets manager and inject at deploy time.","Distinguish config errors (ValueError pre-request) from API errors in monitoring."],"tags":["brave","auth","api-key","environment","search"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}