mastra-ai/mastra · error

Request timed out after ${effectiveTimeout}ms

Error message

Request timed out after ${effectiveTimeout}ms

What it means

requestBrightData wraps its fetch in an AbortController with an effective timeout (client config.timeout or default). When the abort fires, fetch rejects with an AbortError, which this catch block converts into a clearer 'Request timed out after <ms>ms' error. It means Bright Data did not respond within the configured window.

Source

Thrown at integrations/brightdata/src/client.ts:89

      if (response.status === 401 || response.status === 403) {
        throw new Error('invalid API key or insufficient permissions');
      }

      if (response.status === 400) {
        throw new Error(`bad request: ${responseText}`);
      }

      throw new Error(`request failed with status ${response.status}: ${responseText}`);
    }

    if (body.format === 'json') {
      return responseText ? JSON.parse(responseText) : {};
    }

    return responseText;
  } catch (error) {
    if (error instanceof Error && error.name === 'AbortError') {
      throw new Error(`Request timed out after ${effectiveTimeout}ms`);
    }
    throw error;
  } finally {
    clearTimeout(timeoutId);
  }
}

function buildGoogleSearchUrl(query: string, options: SearchOptions = {}) {
  const url = new URL('https://www.google.com/search');
  url.searchParams.set('q', query.trim());
  if ((options.format ?? 'json') === 'json') {
    url.searchParams.set('brd_json', '1');
  }
  url.searchParams.set('hl', options.language ?? 'en');

  if (options.country) {
    url.searchParams.set('gl', options.country);
  }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Increase the timeout passed to getBrightDataClient({ timeout }) or the default budget to cover realistic Bright Data latency.
  2. Retry the request — timeouts are often transient.
  3. Check network egress/proxy configuration between the host and Bright Data.
  4. If queries are consistently slow, reduce result size or use a faster zone.

Example fix

// before
const client = getBrightDataClient({ apiKey, timeout: 1000 });
// after
const client = getBrightDataClient({ apiKey, timeout: 30000 });
Defensive patterns

Strategy: retry

Try / catch

try {
  const result = await client.search.google(query);
} catch (err) {
  if (err instanceof Error && /^Request timed out after \d+ms$/.test(err.message)) {
    // transient — retry once with a larger client timeout or surface a degradation
    return searchWithRetry(query);
  }
  throw err;
}

Prevention

When it happens

Trigger: Any requestBrightData call that exceeds effectiveTimeout — slow Bright Data zone response, large result sets, network latency, or a timeout configured lower than realistic provider latency.

Common situations: timeout option set to a very small value; SERP queries that take several seconds under load; network egress blocked or slow from the host; provider slowdowns.

Understand the failure class

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/d25fe496c86aa424. Report an issue: GitHub.