vercel/ai · error · APICallError

xAI video status response exceeded ${MAX_PENDING_BODY_BYTES}

Error message

xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes

What it means

readPendingBody in the xAI video model reads the polling/status response body with a hard cap of MAX_PENDING_BODY_BYTES. While streaming the status body, if the accumulated bytes exceed the cap, an APICallError is thrown to prevent unbounded memory consumption from a misbehaving or unexpected response. This is a defensive guard, not a normal operational state.

Source

Thrown at packages/xai/src/xai-video-model.ts:726

  url,
  requestBodyValues,
}: Parameters<ResponseHandler<unknown>>[0]): Promise<string> {
  if (response.body == null) {
    return '';
  }

  const reader = response.body.getReader();
  const chunks: Uint8Array[] = [];
  let totalBytes = 0;

  try {
    while (true) {
      const { done, value } = await reader.read();
      if (done) break;

      totalBytes += value.length;
      if (totalBytes > MAX_PENDING_BODY_BYTES) {
        throw new APICallError({
          message: `xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes`,
          url,
          requestBodyValues,
          statusCode: response.status,
          responseHeaders: extractResponseHeaders(response),
        });
      }

      chunks.push(value);
    }
  } finally {
    reader.releaseLock();
  }

  const merged = new Uint8Array(totalBytes);
  let offset = 0;
  for (const chunk of chunks) {
    merged.set(chunk, offset);

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Inspect the actual status URL response (curl it) to see what oversized payload is being returned.
  2. Check proxies/gateways for injected error pages and fix the upstream xAI API reachability.
  3. Retry the status poll; transient server issues often resolve.
  4. Update @ai-sdk/xai; if legitimate status payloads have grown, a newer version may raise or handle the limit.
Defensive patterns

Strategy: retry

Try / catch

try {
  await pollVideoStatus(url);
} catch (e) {
  if (APICallError.isInstance(e) && e.message.includes('exceeded') && e.message.includes('bytes')) {
    // treat as transient/infra issue: log URL + status, retry poll after backoff
  } else throw e;
}

Prevention

When it happens

Trigger: The xAI video status endpoint returns an unexpectedly huge body (e.g. server misconfiguration returning an HTML error page, a proxy dumping a large payload, or an API contract change inflating the status payload).

Common situations: Gateway/captive-portal HTML error pages; debugging endpoints echoing large payloads; misconfigured mock servers in tests; extremely long-running videos if the status payload embeds verbose data.

Related errors


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