FoundationAgents/MetaGPT · error · ValueError

To use google search engine, make sure you provide the `cse_

Error message

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.

What it means

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.

Source

Thrown at metagpt/tools/search_engine_googleapi.py:53

    @model_validator(mode="before")
    @classmethod
    def validate_google(cls, values: dict) -> dict:
        if "google_api_key" in values:
            values.setdefault("api_key", values["google_api_key"])
            warnings.warn("`google_api_key` is deprecated, use `api_key` instead", DeprecationWarning, stacklevel=2)

        if "api_key" not in values:
            raise ValueError(
                "To use google search engine, make sure you provide the `api_key` when constructing an object. You can obtain "
                "an API key from https://console.cloud.google.com/apis/credentials."
            )

        if "google_cse_id" in values:
            values.setdefault("cse_id", values["google_cse_id"])
            warnings.warn("`google_cse_id` is deprecated, use `cse_id` instead", DeprecationWarning, stacklevel=2)

        if "cse_id" not in values:
            raise ValueError(
                "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."
            )
        return values

    @property
    def google_api_client(self):
        build_kwargs = {"developerKey": self.api_key, "discoveryServiceUrl": self.discovery_service_url}
        if self.proxy:
            parse_result = urlparse(self.proxy)
            proxy_type = parse_result.scheme
            if proxy_type == "https":
                proxy_type = "http"
            build_kwargs["http"] = httplib2.Http(
                proxy_info=httplib2.ProxyInfo(
                    getattr(httplib2.socks, f"PROXY_TYPE_{proxy_type.upper()}"),
                    parse_result.hostname,
                    parse_result.port,

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Create a Programmable Search Engine and pass cse_id along with api_key
  2. Add `cse_id` (or legacy `google_cse_id`) to your search engine config
  3. Store both in env/.env so config rendering always includes them

Example fix

# before
engine = GoogleAPIWrapper(api_key=key)  # ValueError: missing cse_id
# after
engine = GoogleAPIWrapper(api_key=key, cse_id=os.environ["GOOGLE_CSE_ID"])
Defensive patterns

Strategy: validation

Validate before calling

import os
cse_id = os.environ.get("GOOGLE_CSE_ID")
if not cse_id:
    raise SystemExit("create a Programmable Search Engine and set GOOGLE_CSE_ID")

Try / catch

try:
    engine = GoogleAPIWrapper(api_key=k, cse_id=c)
except ValueError as e:
    raise ConfigError(str(e))

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/7fb86937316cdeba. Report an issue: GitHub.