Mintplex-Labs/anything-llm · error

- . params: )}

Error message

${res.status} - ${res.statusText}. params: ${JSON.stringify({ auth: this.middleTruncate(process.env.AGENT_BAIDU_SEARCH_API_KEY, 5), q: query, body: body.slice(0, 300) })}

What it means

Thrown inside the Baidu AppBuilder search branch of the web-browsing plugin when the POST (X-Appbuilder-Authorization: Bearer AGENT_BAIDU_SEARCH_API_KEY, body with a user message and resource_type_filter web/top_k 10) returns non-ok. Unlike the siblings, it first reads the response body and includes its first 300 characters in the message alongside status, statusText, query, and the truncated key. The surrounding .catch converts it to a logged 'Baidu Search Error' and an error string for the agent.

Solutions

  1. Set AGENT_BAIDU_SEARCH_API_KEY to a valid Baidu AppBuilder API key and restart the server.
  2. Read the embedded body snippet for Baidu's specific error code (auth vs quota vs param) and act on it.
  3. For 429s, reduce concurrent web_search calls or add backoff; check the AppBuilder console for quota.

Example fix

# before
AGENT_BAIDU_SEARCH_API_KEY=<ernie-bot-key>  # 401 - Unauthorized

# after
AGENT_BAIDU_SEARCH_API_KEY=<appbuilder access key>
# restart server
Defensive patterns

Strategy: validation

Validate before calling

const KEY = process.env.AGENT_BAIDU_SEARCH_API_KEY;
if (!KEY) throw new Error("AGENT_BAIDU_SEARCH_API_KEY not set — configure it and restart");
// pre-flight the AppBuilder endpoint cheaply:
const r = await fetch("https://qianfan.baidubce.com/v2/app", {
  headers: { "X-Appbuilder-Authorization": `Bearer ${KEY}` },
});
if (r.status === 401) throw new Error("Baidu AppBuilder key rejected (401)");

Try / catch

const out = await webSearch(query);
if (typeof out === "string" && out.includes("Baidu Search Error")) {
  // message carries the first 300 chars of Baidu's response body — parse its error code there
  if (/"code":\s*401|Unauthorized/i.test(out)) rotateBaiduKey();
  else if (out.includes("429") || /QPS|limit/i.test(out)) backoffThenRetry(query);
  else logForInspection(out);
}

Prevention

When it happens

Trigger: AGENT_BAIDU_SEARCH_API_KEY missing/invalid (401); AppBuilder QPS or quota limits exceeded (429); malformed request body such as a bad resource_type_filter (400); regional/service unavailability (5xx). Body text in the message pinpoints the API's own error code/description.

Common situations: AppBuilder key expired or the app deleted; using an ERNIE Bot key instead of an AppBuilder access key; .env updated without process restart; QPS spikes when the agent fans out multiple searches.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@a145d4d87d (2026-08-18). Data as JSON: /api/errors/e01a212e72ae6a60. Report an issue: GitHub.

Appendix: source

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

              "https://qianfan.baidubce.com/v2/ai_search/web_search",
              {
                method: "POST",
                headers: {
                  "Content-Type": "application/json",
                  Authorization: `Bearer ${process.env.AGENT_BAIDU_SEARCH_API_KEY}`,
                  "X-Appbuilder-Authorization": `Bearer ${process.env.AGENT_BAIDU_SEARCH_API_KEY}`,
                },
                body: JSON.stringify({
                  messages: [{ role: "user", content: query }],
                  resource_type_filter: [{ type: "web", top_k: 10 }],
                }),
              }
            )
              .then(async (res) => {
                if (res.ok) return res.json();

                const body = await res.text().catch(() => "");
                throw new Error(
                  `${res.status} - ${res.statusText}. params: ${JSON.stringify({
                    auth: this.middleTruncate(
                      process.env.AGENT_BAIDU_SEARCH_API_KEY,
                      5
                    ),
                    q: query,
                    body: body.slice(0, 300),
                  })}`
                );
              })
              .then((data) => {
                return { response: data, error: null };
              })
              .catch((e) => {
                this.super.handlerProps.log(`Baidu Search Error: ${e.message}`);
                return { response: null, error: e.message };
              });

View on GitHub (pinned to a145d4d87d)