{"record":{"id":"ada0619ce5257147","repo":"assafelovic/gpt-researcher","slug":"searchapi-key-not-found-please-set-the-searchapi","errorCode":null,"errorMessage":"SearchApi key not found. Please set the SEARCHAPI_API_KEY environment variable. You can get a key at https://www.searchapi.io/","messagePattern":"SearchApi key not found\\. Please set the SEARCHAPI_API_KEY environment variable\\. You can get a key at https://www\\.searchapi\\.io/","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"gpt_researcher/retrievers/searchapi/searchapi.py","lineNumber":32,"sourceCode":"    def __init__(self, query, query_domains=None):\n        \"\"\"\n        Initializes the SearchApiSearch object\n        Args:\n            query:\n        \"\"\"\n        self.query = query\n        self.api_key = self.get_api_key()\n\n    def get_api_key(self):\n        \"\"\"\n        Gets the SearchApi API key\n        Returns:\n\n        \"\"\"\n        try:\n            api_key = os.environ[\"SEARCHAPI_API_KEY\"]\n        except Exception:\n            raise Exception(\"SearchApi key not found. Please set the SEARCHAPI_API_KEY environment variable. \"\n                            \"You can get a key at https://www.searchapi.io/\")\n        return api_key\n\n    def search(self, max_results=7):\n        \"\"\"\n        Searches the query\n        Returns:\n\n        \"\"\"\n        print(\"SearchApiSearch: Searching with query {0}...\".format(self.query))\n        \"\"\"Useful for general internet search queries using SearchApi.\"\"\"\n\n\n        url = \"https://www.searchapi.io/api/v1/search\"\n        params = {\n            \"q\": self.query,\n            \"engine\": \"google\",\n        }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/retrievers/searchapi/searchapi.py#L14-L50","documentation":"Exception raised by the SearchApi retriever when the SEARCHAPI_API_KEY environment variable is missing; the failed os.environ lookup is caught and re-raised with this message. searchapi.io requires this key for authentication.","triggerScenarios":"Instantiating the SearchApi retriever (get_api_key() called from __init__) in an environment without SEARCHAPI_API_KEY.","commonSituations":"Key not set, .env not loaded, or the variable missing in Docker/CI deployment environments.","solutions":["export SEARCHAPI_API_KEY=<key> (get one at https://www.searchapi.io/).","Add it to .env / secrets and confirm loading before retriever creation.","In CI, register it as a secret environment variable."],"exampleFix":"# before\nretriever = SearchApi(query=\"...\")\n\n# after\nimport os\nassert os.environ.get(\"SEARCHAPI_API_KEY\"), \"Set SEARCHAPI_API_KEY\"\nretriever = SearchApi(query=\"...\")","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"SEARCHAPI_API_KEY\"):\n    raise SystemExit(\"Set SEARCHAPI_API_KEY (https://www.searchapi.io/\")","typeGuard":"null","tryCatchPattern":"try:\n    retriever = SearchApi(query)\nexcept Exception as e:\n    if \"SEARCHAPI_API_KEY\" in str(e):\n        sys.exit(str(e))\n    raise","preventionTips":["Add the key to .env/secrets and preflight at boot.","Verify presence in CI environment variables."],"tags":["searchapi","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"}