{"record":{"id":"983bef8f8f01d6b7","repo":"assafelovic/gpt-researcher","slug":"exa-api-key-not-found-please-set-the-exa-api-key","errorCode":null,"errorMessage":"Exa API key not found. Please set the EXA_API_KEY environment variable. You can obtain your key from https://exa.ai/","messagePattern":"Exa API key not found\\. Please set the EXA_API_KEY environment variable\\. You can obtain your key from https://exa\\.ai/","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"gpt_researcher/retrievers/exa/exa.py","lineNumber":35,"sourceCode":"        check_pkg(\"exa_py\")\n        from exa_py import Exa\n        self.query = query\n        self.api_key = self._retrieve_api_key()\n        self.client = Exa(api_key=self.api_key)\n        self.query_domains = query_domains or None\n\n    def _retrieve_api_key(self):\n        \"\"\"\n        Retrieves the Exa API key from environment variables.\n        Returns:\n            The API key.\n        Raises:\n            Exception: If the API key is not found.\n        \"\"\"\n        try:\n            api_key = os.environ[\"EXA_API_KEY\"]\n        except KeyError:\n            raise Exception(\n                \"Exa API key not found. Please set the EXA_API_KEY environment variable. \"\n                \"You can obtain your key from https://exa.ai/\"\n            )\n        return api_key\n\n    def search(\n        self, max_results=10, use_autoprompt=False, search_type=\"neural\", **filters\n    ):\n        \"\"\"\n        Searches the query using the Exa API.\n        Args:\n            max_results: The maximum number of results to return.\n            use_autoprompt: Whether to use autoprompting.\n            search_type: The type of search (e.g., \"neural\", \"keyword\").\n            **filters: Additional filters (e.g., date range, domains).\n        Returns:\n            A list of search results.\n        \"\"\"","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/retrievers/exa/exa.py#L17-L53","documentation":"Exception raised by the Exa retriever when the EXA_API_KEY environment variable is absent (KeyError on os.environ lookup). Exa (formerly Metaphor) requires a bearer key for every search request.","triggerScenarios":"Constructing the Exa retriever; __init__ calls _retrieve_api_key(), which raises when EXA_API_KEY is not set.","commonSituations":"Missing export, .env not loaded, key set only in local shell but app runs under a different user/service, or CI pipeline lacking the secret.","solutions":["export EXA_API_KEY=<key> (obtain at https://exa.ai).","Add EXA_API_KEY to .env / your secret manager and ensure it loads before retriever creation.","In CI/CD, add it as a masked environment variable."],"exampleFix":"# before\nretriever = Exa(query=\"...\")\n\n# after\nimport os\nif not os.environ.get(\"EXA_API_KEY\"):\n    raise SystemExit(\"EXA_API_KEY missing — get one at https://exa.ai/\")\nretriever = Exa(query=\"...\")","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"EXA_API_KEY\"):\n    raise SystemExit(\"Set EXA_API_KEY (https://exa.ai)\")","typeGuard":"null","tryCatchPattern":"try:\n    retriever = Exa(query)\nexcept Exception as e:\n    if \"EXA_API_KEY\" in str(e):\n        sys.exit(str(e))\n    raise","preventionTips":["Add EXA_API_KEY to your secret store and startup preflight.","Confirm the var is present in the process env (printenv) after deploying."],"tags":["exa","missing-env-var","api-key","retriever"],"backgroundTag":"missing-env-var","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}