FoundationAgents/MetaGPT · error · ValueError
Got error from SerpAPI: {res['error']}
Error message
Got error from SerpAPI: {res['error']} What it means
ValueError from SerperAPIWrapper._process_response: the SerpAPI HTTP call succeeded but the JSON payload contains an 'error' key. The only tolerated error is the specific 'Google hasn't returned any results for this query.' string (mapped to 'No good search result found'); every other upstream error string is re-raised verbatim.
Source
Thrown at metagpt/tools/search_engine_serpapi.py:90
_params = {
"api_key": self.api_key,
"q": query,
}
params = {**self.params, **_params}
return params
@staticmethod
def _process_response(res: dict, as_string: bool) -> str:
"""Process response from SerpAPI."""
# logger.debug(res)
focus = ["title", "snippet", "link"]
get_focused = lambda x: {i: j for i, j in x.items() if i in focus}
if "error" in res.keys():
if res["error"] == "Google hasn't returned any results for this query.":
toret = "No good search result found"
else:
raise ValueError(f"Got error from SerpAPI: {res['error']}")
elif "answer_box" in res.keys() and "answer" in res["answer_box"].keys():
toret = res["answer_box"]["answer"]
elif "answer_box" in res.keys() and "snippet" in res["answer_box"].keys():
toret = res["answer_box"]["snippet"]
elif "answer_box" in res.keys() and "snippet_highlighted_words" in res["answer_box"].keys():
toret = res["answer_box"]["snippet_highlighted_words"][0]
elif "sports_results" in res.keys() and "game_spotlight" in res["sports_results"].keys():
toret = res["sports_results"]["game_spotlight"]
elif "knowledge_graph" in res.keys() and "description" in res["knowledge_graph"].keys():
toret = res["knowledge_graph"]["description"]
elif "snippet" in res["organic_results"][0].keys():
toret = res["organic_results"][0]["snippet"]
else:
toret = "No good search result found"
toret_l = []
if "answer_box" in res.keys() and "snippet" in res["answer_box"].keys():
toret_l += [get_focused(res["answer_box"])]View on GitHub (pinned to 11cdf466d0)
Solutions
- Inspect the embedded error string: 'Invalid API key' -> update the key; quota/credit messages -> top up or wait
- Wrap run/results in try/except ValueError and retry with backoff for transient upstream errors
- Check account status at serpapi.com if errors persist with a valid key
Example fix
# before
results = await serpapi.run(query)
# after
try:
results = await serpapi.run(query)
except ValueError as e:
if "Invalid API key" in str(e):
raise # credential problem: fix the key
await asyncio.sleep(5) # transient upstream error: back off and retry
results = await serpapi.run(query) Defensive patterns
Strategy: retry
Try / catch
import asyncio
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=2, max=30), retry_error_cb=lambda e: 'Invalid API key' not in str(e))
async def search(serpapi, query):
return await serpapi.run(query) Prevention
- Classify the embedded error string: credential errors are permanent, quota/transient ones are retryable
- Monitor credit usage before batch runs
- Alert on repeated upstream errors rather than swallowing them
When it happens
Trigger: Invalid or expired API key; exhausted plan credits; rate limiting; malformed query parameters — any SerpAPI response whose 'error' field differs from the no-results string.
Common situations: Key rotated but code/config still holds the old one; free tier quota hit during batch research runs; transient upstream errors surfacing mid-pipeline.
Related errors
- Got error from SerpAPI: {res['error']}
- To use serpapi search engine, make sure you provide the `api
- To use google search engine, make sure you provide the `api_
- To use google search engine, make sure you provide the `cse_
- To use serper search engine, make sure you provide the `api_
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/06328b926de2d25c.
Report an issue: GitHub.