{"record":{"id":"98ec0b31b8fb3e82","repo":"assafelovic/gpt-researcher","slug":"google-api-key-not-found-please-set-the-google-ap","errorCode":null,"errorMessage":"Google API key not found. Please set the GOOGLE_API_KEY environment variable. You can get a key at https://developers.google.com/custom-search/v1/overview","messagePattern":"Google API key not found\\. Please set the GOOGLE_API_KEY environment variable\\. You can get a key at https://developers\\.google\\.com/custom-search/v1/overview","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"gpt_researcher/retrievers/google/google.py","lineNumber":36,"sourceCode":"            query:\n        \"\"\"\n        self.query = query\n        self.headers = headers or {}\n        self.query_domains = query_domains or None\n        self.api_key = self.headers.get(\"google_api_key\") or self.get_api_key()  # Use the passed api_key or fallback to environment variable\n        self.cx_key = self.headers.get(\"google_cx_key\") or self.get_cx_key()  # Use the passed cx_key or fallback to environment variable\n\n    def get_api_key(self):\n        \"\"\"\n        Gets the Google API key\n        Returns:\n\n        \"\"\"\n        # Get the API key\n        try:\n            api_key = os.environ[\"GOOGLE_API_KEY\"]\n        except Exception:\n            raise Exception(\"Google API key not found. Please set the GOOGLE_API_KEY environment variable. \"\n                            \"You can get a key at https://developers.google.com/custom-search/v1/overview\")\n        return api_key\n\n    def get_cx_key(self):\n        \"\"\"\n        Gets the Google CX key\n        Returns:\n\n        \"\"\"\n        # Get the API key\n        try:\n            api_key = os.environ[\"GOOGLE_CX_KEY\"]\n        except Exception:\n            raise Exception(\"Google CX key not found. Please set the GOOGLE_CX_KEY environment variable. \"\n                            \"You can get a key at https://developers.google.com/custom-search/v1/overview\")\n        return api_key\n\n    def search(self, max_results=7):","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/retrievers/google/google.py#L18-L54","documentation":"Exception raised by the Google retriever when the GOOGLE_API_KEY environment variable is missing (any failure of the os.environ lookup is caught and re-raised). Google Custom Search JSON API requires this key alongside the CX id.","triggerScenarios":"Instantiating the Google retriever; __init__ calls get_api_key(), which raises when GOOGLE_API_KEY is unset.","commonSituations":"Missing Google Cloud API key, .env not loaded, or only GOOGLE_CX_KEY set — both GOOGLE_API_KEY and GOOGLE_CX_KEY are needed.","solutions":["Create an API key in Google Cloud and export GOOGLE_API_KEY.","Also set GOOGLE_CX_KEY (the custom search engine id) — both are required.","Add both to .env and verify loading before retriever construction."],"exampleFix":"# before\nretriever = Google(query=\"...\")\n\n# after\nimport os\nfor var in (\"GOOGLE_API_KEY\", \"GOOGLE_CX_KEY\"):\n    assert os.environ.get(var), f\"{var} missing\"\nretriever = Google(query=\"...\")","handlingStrategy":"validation","validationCode":"import os\nmissing = [v for v in (\"GOOGLE_API_KEY\", \"GOOGLE_CX_KEY\") if not os.environ.get(v)]\nif missing:\n    raise SystemExit(f\"Missing env vars: {missing}\")","typeGuard":"null","tryCatchPattern":"try:\n    retriever = Google(query)\nexcept Exception as e:\n    if \"GOOGLE_API_KEY\" in str(e) or \"GOOGLE_CX_KEY\" in str(e):\n        sys.exit(str(e))\n    raise","preventionTips":["Always set both GOOGLE_API_KEY and GOOGLE_CX_KEY together.","Validate both vars in a startup preflight.","Document the pair in deployment templates."],"tags":["google","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"}