{"record":{"id":"22099e216f9294f0","repo":"assafelovic/gpt-researcher","slug":"google-cx-key-not-found-please-set-the-google-cx","errorCode":null,"errorMessage":"Google CX key not found. Please set the GOOGLE_CX_KEY environment variable. You can get a key at https://developers.google.com/custom-search/v1/overview","messagePattern":"Google CX key not found\\. Please set the GOOGLE_CX_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":50,"sourceCode":"        # 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):\n        \"\"\"\n        Searches the query using Google Custom Search API, optionally restricting to specific domains\n        Returns:\n            list: List of search results with title, href and body\n        \"\"\"\n        # Build query with domain restrictions if specified\n        search_query = self.query\n        if self.query_domains and len(self.query_domains) > 0:\n            domain_query = \" OR \".join([f\"site:{domain}\" for domain in self.query_domains])\n            search_query = f\"({domain_query}) {self.query}\"\n\n        print(\"Searching with query {0}...\".format(search_query))\n\n        # URL-encode every parameter. Interpolating the raw query broke any","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/retrievers/google/google.py#L32-L68","documentation":"Exception raised by the Google retriever's get_cx_key() when the GOOGLE_CX_KEY environment variable is missing. The CX key is the Custom Search Engine ID; without it Google search queries cannot be scoped and the retriever refuses to construct.","triggerScenarios":"Instantiating the Google retriever with GOOGLE_API_KEY set but GOOGLE_CX_KEY absent; __init__ calls get_cx_key() which raises.","commonSituations":"Developer sets only the API key and forgets the search-engine ID, or the CX var name is mistyped in .env/compose.","solutions":["Create a Custom Search Engine at https://programmablesearchengine.google.com/ and copy its ID.","export GOOGLE_CX_KEY=<engine id> (add to .env).","Restart the app so the new variable is loaded before retriever creation."],"exampleFix":"# before\n# .env has only GOOGLE_API_KEY\nretriever = Google(query=\"...\")\n\n# after\n# .env\nGOOGLE_API_KEY=...\nGOOGLE_CX_KEY=a1b2c3d4e5f6g7h8i9\nretriever = Google(query=\"...\")","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"GOOGLE_CX_KEY\"):\n    raise SystemExit(\"Set GOOGLE_CX_KEY to your Programmable Search Engine ID\")","typeGuard":"null","tryCatchPattern":"try:\n    retriever = Google(query)\nexcept Exception as e:\n    if \"GOOGLE_CX_KEY\" in str(e):\n        sys.exit(str(e))\n    raise","preventionTips":["Create the Programmable Search Engine first, then copy its cx id into env.","Pair it with GOOGLE_API_KEY in the same config block.","Preflight both variables at startup."],"tags":["google","missing-env-var","custom-search","retriever"],"backgroundTag":"missing-env-var","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}