{"record":{"id":"dfae8b438537ec9e","repo":"huggingface/smolagents","slug":"missing-api-key-make-sure-you-have-exa-api-key","errorCode":null,"errorMessage":"Missing API key. Make sure you have 'EXA_API_KEY' in your env variables.","messagePattern":"Missing API key\\. Make sure you have 'EXA_API_KEY' in your env variables\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/default_tools.py","lineNumber":463,"sourceCode":"        results = [\n            {\n                \"title\": item.findtext(\"title\"),\n                \"link\": item.findtext(\"link\"),\n                \"description\": item.findtext(\"description\"),\n            }\n            for item in items[: self.max_results]\n        ]\n        return results\n\n    def search_exa(self, query: str) -> list:\n        \"\"\"Search using the Exa API. Requires an EXA_API_KEY environment variable.\"\"\"\n        import os\n\n        import requests\n\n        api_key = os.getenv(\"EXA_API_KEY\")\n        if not api_key:\n            raise ValueError(\"Missing API key. Make sure you have 'EXA_API_KEY' in your env variables.\")\n\n        response = requests.post(\n            \"https://api.exa.ai/search\",\n            headers={\n                \"x-api-key\": api_key,\n                \"Content-Type\": \"application/json\",\n                \"x-exa-integration\": \"smolagents\",\n            },\n            json={\n                \"query\": query,\n                \"numResults\": self.max_results,\n                \"contents\": {\"highlights\": True},\n            },\n            timeout=getattr(self, \"timeout\", 30),\n        )\n        response.raise_for_status()\n        data = response.json()\n        return [","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L445-L481","documentation":"Raised by SearchEngineTool.search_exa when the EXA_API_KEY environment variable is unset or empty. The key is read lazily at search time (not construction), so a tool built without a key fails only when an Exa search is actually executed.","triggerScenarios":"SearchEngineTool(engine='exa') with no EXA_API_KEY in env, then calling run/search. Also fails when the var exists but is an empty string, since the check is `if not api_key`.","commonSituations":"Missing .env loading in notebooks/containers, keys set in the deployment shell but not in the app process, or forgetting that the exa path needs its own key separate from serper/serpapi keys.","solutions":["export EXA_API_KEY=... (get one at exa.ai) before running, and load .env files before tool use.","If using dotenv, ensure load_dotenv() executes before the first search call.","Verify with os.getenv('EXA_API_KEY') in the failing process."],"exampleFix":"# before\ntool = SearchEngineTool(engine='exa'); tool.run('x')  # ValueError at search time\n# after\nimport os\nos.environ['EXA_API_KEY'] = '...'\ntool.run('x')","handlingStrategy":"validation","validationCode":"import os\nif not os.getenv('EXA_API_KEY'): raise SystemExit('set EXA_API_KEY before using engine=exa')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the key is checked at search time, not construction — validate early yourself.","Keep per-engine keys in one env-loading module."],"tags":["missing-env-var","api-key","search-tool","smolagents"],"backgroundTag":"missing-env-var","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}