Mintplex-Labs/anything-llm · error · Error

API Call failed: ${error.message}

Error message

API Call failed: ${error.message}

What it means

The top-level catch-all in executeApiCall(). Every failure inside the function - the HTTP error (381), a network-level fetch rejection, or a safeJsonParse failure on the response body - is caught here, logged via console.error, and re-thrown as a single wrapped error. Callers receive this message rather than the underlying cause.

Source

Thrown at server/utils/agentFlows/executors/api-call.js:56

  }

  try {
    introspect(`Sending body to ${url}: ${requestConfig?.body || "No body"}`);
    const response = await fetch(url, requestConfig);
    if (!response.ok) {
      introspect(`Request failed with status ${response.status}`);
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    introspect(`API call completed`);
    return await response
      .text()
      .then((text) =>
        safeJsonParse(text, "Failed to parse output from API call block")
      );
  } catch (error) {
    console.error(error);
    throw new Error(`API Call failed: ${error.message}`);
  }
}

module.exports = executeApiCall;

View on GitHub (pinned to 526360e320)

Solutions

  1. Read error.message: if it contains "HTTP error! status", treat as an HTTP status problem (see 381); if it contains "Failed to parse", the response was not valid JSON.
  2. Confirm the host is reachable and the URL scheme is correct (https vs http).
  3. If the endpoint legitimately returns non-JSON, that is unsupported by this executor - point the flow at a JSON-returning endpoint.
  4. Check server logs (console.error output) for the original error object with its full stack.
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: confirm the host resolves and the URL is well-formed
function validateApiUrl(url) {
  try { new URL(url); } catch { throw new Error(`Invalid API url: ${url}`); }
}

Try / catch

try {
  result = await executeApiCall(config, context);
} catch (error) {
  // error.message is "API Call failed: <cause>"; inspect the cause substring
  if (/status: 4\d\d/.test(error.message)) handleClientError(error);
  else if (/Failed to parse/.test(error.message)) handleNonJsonResponse(error);
  else handleNetworkError(error);
}

Prevention

When it happens

Trigger: Any of: fetch() rejects (DNS failure, connection refused, invalid URL, timeout); response.ok is false (becomes 381 then re-wrapped here); or response.text() cannot be parsed as JSON by safeJsonParse, which returns the fallback string "Failed to parse output from API call block" that then becomes this error.

Common situations: Offline or unreachable host; misspelled domain; the API returns HTML or plain text instead of JSON; self-signed certificate with no handling; a non-JSON 200 response.

Related errors


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