vercel/ai · error · APICallError

Failed to process error response

Error message

Failed to process error response

What it means

getFromApi received an error-status HTTP response, but while building/processing the APICallError from the error body, an unexpected exception occurred. The library wraps that unexpected parsing/processing failure in a new APICallError with this message, preserving the original failure as `cause`. It signals that the provider's error response could not be handled normally (e.g. non-JSON error body).

Source

Thrown at packages/provider-utils/src/get-from-api.ts:116

    if (!response.ok) {
      let errorInformation: {
        value: Error;
        responseHeaders?: Record<string, string> | undefined;
      };

      try {
        errorInformation = await failedResponseHandler({
          response,
          url,
          requestBodyValues: {},
        });
      } catch (error) {
        if (isAbortError(error) || APICallError.isInstance(error)) {
          throw error;
        }

        throw new APICallError({
          message: 'Failed to process error response',
          cause: error,
          statusCode: response.status,
          url,
          responseHeaders,
          requestBodyValues: {},
        });
      }

      throw errorInformation.value;
    }

    try {
      return await successfulResponseHandler({
        response,
        url,
        requestBodyValues: {},
      });

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Inspect `error.cause` (and the original provider response if logged) to find the underlying failure
  2. Check whether a proxy, gateway, or custom `fetch` is returning non-JSON error bodies (HTML error pages)
  3. Retry the request; if intermittent, it may be a transient network/gateway problem
  4. Capture the full error (message, cause, url, statusCode) and report to the provider package maintainers if the error body is valid JSON yet still fails

Example fix

// inspecting the wrapped failure
try {
  await result;
} catch (error) {
  if (APICallError.isInstance(error) && error.message === 'Failed to process error response') {
    console.error('underlying cause:', error.cause, 'status:', error.statusCode, 'url:', error.url);
  }
}
Defensive patterns

Strategy: try-catch

Type guard

function isFailedToProcessErrorResponse(e: unknown): e is APICallError {
  return APICallError.isInstance(e) && e.message === 'Failed to process error response';
}

Try / catch

try {
  await getFromApi({ url, successfulResponseHandler: ... });
} catch (error) {
  if (isAbortError(error) || APICallError.isInstance(error)) {
    console.error('status:', error.statusCode, 'cause:', error.cause);
  }
}

Prevention

When it happens

Trigger: A fetch inside getFromApi returned a non-2xx status, and the code path that parses the error body (e.g. safeParseJSON of the response or constructing APICallError) threw something that is neither an AbortError nor an APICallError — such as a body-stream read failure or an unexpected runtime exception in response processing.

Common situations: Provider returns an HTML error page (proxy/CDN 502 page) instead of JSON; the response body stream errors mid-read; a corrupted or truncated error response; custom fetch implementations returning malformed Response objects.

Related errors


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