Mintplex-Labs/anything-llm · error · Error

${res.status} - ${res.statusText}. params: ${JSON.stringify(

Error message

${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_SERPAPI_API_KEY, 5), q: query })}

What it means

Thrown inside the SerpApi search provider when fetch() to https://serpapi.com/search.json returns a non-OK HTTP status (anything outside 200–299). The error includes the status code, status text, a middle-truncated view of the API key, and the query. The .catch downstream logs the error and returns a user-facing string, so this error is caught but the search fails.

Source

Thrown at server/utils/agents/aibitat/plugins/web-browsing.js:196

            );

            const engine = process.env.AGENT_SERPAPI_ENGINE;
            const queryParamKey = engine === "amazon" ? "k" : "q";

            const params = new URLSearchParams({
              engine: engine,
              [queryParamKey]: query,
              api_key: process.env.AGENT_SERPAPI_API_KEY,
            });

            const url = `https://serpapi.com/search.json?${params.toString()}`;
            const { response, error } = await fetch(url, {
              method: "GET",
              headers: {},
            })
              .then((res) => {
                if (res.ok) return res.json();
                throw new Error(
                  `${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_SERPAPI_API_KEY, 5), q: query })}`
                );
              })
              .then((data) => {
                return { response: data, error: null };
              })
              .catch((e) => {
                this.super.handlerProps.log(`SerpApi Error: ${e.message}`);
                return { response: null, error: e.message };
              });
            if (error)
              return `There was an error searching for content. ${error}`;

            const data = [];

            switch (engine) {
              case "google":
                if (response.hasOwnProperty("knowledge_graph"))

View on GitHub (pinned to 526360e320)

Solutions

  1. Verify AGENT_SERPAPI_API_KEY is set and valid in the environment (check server settings or .env).
  2. Check the truncated key in the error matches what you expect — if it shows undefined, the env var is not set.
  3. A 429 or 402 means you need to upgrade your SerpApi plan or wait for quota reset.
  4. A 401 means the key is wrong — regenerate it from the SerpApi dashboard and update the setting.
  5. Retry after a brief delay for transient 5xx errors.

Example fix

// before
if (res.ok) return res.json();
throw new Error(`${res.status} - ${res.statusText}. params: ${JSON.stringify({auth: ..., q: query})}`);

// caller-side fix — check key before calling
if (!process.env.AGENT_SERPAPI_API_KEY) {
  return "AGENT_SERPAPI_API_KEY is not configured. Set it in the server environment.";
}
// proceed with fetch
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.AGENT_SERPAPI_API_KEY) {
  throw new Error("AGENT_SERPAPI_API_KEY is not set. Configure it to use SerpApi search.");
}
// Optionally validate key format before the request

Try / catch

try {
  const results = await serpApiSearch(query);
  return results;
} catch (e) {
  if (e.message.startsWith("4") || e.message.includes("401")) {
    return "SerpApi authentication or quota error. Check AGENT_SERPAPI_API_KEY and plan status.";
  }
  // Retry once for 5xx
  if (e.message.startsWith("5")) {
    return await serpApiSearch(query); // single retry
  }
  throw e;
}

Prevention

When it happens

Trigger: SerpApi returns 401 (invalid/missing AGENT_SERPAPI_API_KEY), 429 (rate limit or quota exhausted), 402 (payment required — free tier exhausted), 400 (malformed query), or 5xx (SerpApi outage). The key may be unset, expired, or lack credits.

Common situations: API key was never set in environment; key was revoked or rotated; free-tier searches depleted; sudden burst of agent searches hitting the rate limit; SerpApi upstream incident; query contains characters SerpApi rejects.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/a68e8d69a778792c. Report an issue: GitHub.