{"record":{"id":"7fb86937316cdeba","repo":"FoundationAgents/MetaGPT","slug":"to-use-google-search-engine-make-sure-you-provide-7fb869","errorCode":null,"errorMessage":"To use google search engine, make sure you provide the `cse_id` when constructing an object. You can obtain the cse_id from https://programmablesearchengine.google.com/controlpanel/create.","messagePattern":"To use google search engine, make sure you provide the `cse_id` when constructing an object\\. You can obtain the cse_id from https://programmablesearchengine\\.google\\.com/controlpanel/create\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/tools/search_engine_googleapi.py","lineNumber":53,"sourceCode":"    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_google(cls, values: dict) -> dict:\n        if \"google_api_key\" in values:\n            values.setdefault(\"api_key\", values[\"google_api_key\"])\n            warnings.warn(\"`google_api_key` is deprecated, use `api_key` instead\", DeprecationWarning, stacklevel=2)\n\n        if \"api_key\" not in values:\n            raise ValueError(\n                \"To use google search engine, make sure you provide the `api_key` when constructing an object. You can obtain \"\n                \"an API key from https://console.cloud.google.com/apis/credentials.\"\n            )\n\n        if \"google_cse_id\" in values:\n            values.setdefault(\"cse_id\", values[\"google_cse_id\"])\n            warnings.warn(\"`google_cse_id` is deprecated, use `cse_id` instead\", DeprecationWarning, stacklevel=2)\n\n        if \"cse_id\" not in values:\n            raise ValueError(\n                \"To use google search engine, make sure you provide the `cse_id` when constructing an object. You can obtain \"\n                \"the cse_id from https://programmablesearchengine.google.com/controlpanel/create.\"\n            )\n        return values\n\n    @property\n    def google_api_client(self):\n        build_kwargs = {\"developerKey\": self.api_key, \"discoveryServiceUrl\": self.discovery_service_url}\n        if self.proxy:\n            parse_result = urlparse(self.proxy)\n            proxy_type = parse_result.scheme\n            if proxy_type == \"https\":\n                proxy_type = \"http\"\n            build_kwargs[\"http\"] = httplib2.Http(\n                proxy_info=httplib2.ProxyInfo(\n                    getattr(httplib2.socks, f\"PROXY_TYPE_{proxy_type.upper()}\"),\n                    parse_result.hostname,\n                    parse_result.port,","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/tools/search_engine_googleapi.py#L35-L71","documentation":"ValueError from GoogleAPIWrapper's model_validator: the constructor values lack cse_id (or the deprecated google_cse_id alias). Google's API needs both an API key and a Programmable Search Engine ID (cse_id); the validator maps google_cse_id -> cse_id with a DeprecationWarning before this check, so either field name satisfies it.","triggerScenarios":"GoogleAPIWrapper(api_key='...') without cse_id; config yaml defines the key but not the cse_id; legacy config uses google_cse_id but it was removed during migration.","commonSituations":"Developer obtained an API key but never created a Programmable Search Engine at programmablesearchengine.google.com; config template copied without filling the cse_id field.","solutions":["Create a Programmable Search Engine and pass cse_id along with api_key","Add `cse_id` (or legacy `google_cse_id`) to your search engine config","Store both in env/.env so config rendering always includes them"],"exampleFix":"# before\nengine = GoogleAPIWrapper(api_key=key)  # ValueError: missing cse_id\n# after\nengine = GoogleAPIWrapper(api_key=key, cse_id=os.environ[\"GOOGLE_CSE_ID\"])","handlingStrategy":"validation","validationCode":"import os\ncse_id = os.environ.get(\"GOOGLE_CSE_ID\")\nif not cse_id:\n    raise SystemExit(\"create a Programmable Search Engine and set GOOGLE_CSE_ID\")","typeGuard":null,"tryCatchPattern":"try:\n    engine = GoogleAPIWrapper(api_key=k, cse_id=c)\nexcept ValueError as e:\n    raise ConfigError(str(e))","preventionTips":["Create the Programmable Search Engine ID at the same time you obtain the API key","Validate both fields in one startup config check","Migrate legacy google_cse_id entries to cse_id"],"tags":["search","google","config","credentials","pydantic"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}