vercel/ai · error · InvalidArgumentError

maxRetries must be >= 0

Error message

maxRetries must be >= 0

What it means

Error "maxRetries must be >= 0" thrown in vercel/ai.

Source

Thrown at packages/ai/src/util/prepare-retries.ts:27

  abortSignal,
}: {
  maxRetries: number | undefined;
  abortSignal: AbortSignal | undefined;
}): {
  maxRetries: number;
  retry: RetryFunction;
} {
  if (maxRetries != null) {
    if (!Number.isInteger(maxRetries)) {
      throw new InvalidArgumentError({
        parameter: 'maxRetries',
        value: maxRetries,
        message: 'maxRetries must be an integer',
      });
    }

    if (maxRetries < 0) {
      throw new InvalidArgumentError({
        parameter: 'maxRetries',
        value: maxRetries,
        message: 'maxRetries must be >= 0',
      });
    }
  }

  const maxRetriesResult = maxRetries ?? 2;

  return {
    maxRetries: maxRetriesResult,
    retry: retryWithExponentialBackoffRespectingRetryHeaders({
      maxRetries: maxRetriesResult,
      abortSignal,
    }),
  };
}

View on GitHub (pinned to 69428b1f8b)

When it happens

Trigger: Thrown at packages/ai/src/util/prepare-retries.ts:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/eee86f1ae195b6cc. Report an issue: GitHub.