vercel/ai · error · APICallError

Failed to process successful response

Error message

Failed to process successful response

What it means

getFromApi received a successful (2xx) HTTP response, but an exception occurred while reading or processing the response body (e.g. JSON parsing or transformation). The library re-throws abort errors and APICallErrors unchanged, and wraps any other failure in an APICallError with this message, keeping the original error as `cause`.

Source

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

      }

      throw errorInformation.value;
    }

    try {
      return await successfulResponseHandler({
        response,
        url,
        requestBodyValues: {},
      });
    } catch (error) {
      if (error instanceof Error) {
        if (isAbortError(error) || APICallError.isInstance(error)) {
          throw error;
        }
      }

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

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Inspect `error.cause` to identify the underlying body-processing failure
  2. Verify the endpoint actually returns JSON with status 200 (curl the URL / check provider status page)
  3. Check any custom `fetch` wrapper for interference with response body reading
  4. Retry; if the 200-with-bad-body persists, capture url/status/headers and report to the provider package maintainers

Example fix

try {
  await result;
} catch (error) {
  if (APICallError.isInstance(error) && error.message === 'Failed to process successful response') {
    console.error('status was 200 but body processing failed:', error.cause);
  }
}
Defensive patterns

Strategy: try-catch

Type guard

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

Try / catch

try {
  await getFromApi({ url, successfulResponseHandler: jsonResponseHandler });
} catch (error) {
  if (APICallError.isInstance(error) && error.statusCode === 200) {
    console.error('200 but body processing failed:', error.cause);
  }
}

Prevention

When it happens

Trigger: A fetch inside getFromApi returned status 2xx, then response.json()/body consumption threw a non-abort, non-APICallError exception — e.g. invalid JSON in a 200 response, or the body stream failing while being read.

Common situations: Misbehaving proxy or middleware returning 200 with an HTML/empty body; custom fetch implementations that break streaming; interrupted connections after headers were received; provider returning malformed JSON payloads on success.

Related errors


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