vercel/ai · error · EmptyResponseBodyError

AI_EmptyResponseBodyError

AI_EmptyResponseBodyError

Error message

Empty response body

What it means

The Bedrock event-stream response handler requires an HTTP response body to decode events. When response.body is null (no content), it throws AI_EmptyResponseBodyError. Bedrock streaming endpoints should always return a body, so this usually signals a request or infrastructure problem.

Source

Thrown at packages/amazon-bedrock/src/amazon-bedrock-event-stream-response-handler.ts:20

import {
  safeParseJSON,
  extractResponseHeaders,
  safeValidateTypes,
  type ParseResult,
  type ResponseHandler,
} from '@ai-sdk/provider-utils';
import type { ZodType } from 'zod/v4';
import { createAmazonBedrockEventStreamDecoder } from './amazon-bedrock-event-stream-decoder';

export const createAmazonBedrockEventStreamResponseHandler =
  <T>(
    chunkSchema: ZodType<T, any>,
  ): ResponseHandler<ReadableStream<ParseResult<T>>> =>
  async ({ response }: { response: Response }) => {
    const responseHeaders = extractResponseHeaders(response);

    if (response.body == null) {
      throw new EmptyResponseBodyError({});
    }

    return {
      responseHeaders,
      value: createAmazonBedrockEventStreamDecoder<ParseResult<T>>(
        response.body,
        async (event, controller) => {
          const payloadType =
            event.messageType === 'event'
              ? event.eventType
              : event.messageType === 'exception'
                ? event.exceptionType
                : undefined;

          if (payloadType == null) {
            return;
          }

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Verify the modelId and region are correct and the model is enabled for your account
  2. Log the raw response status/headers to see what Bedrock actually returned
  3. Remove any custom fetch wrapper that could consume or drop response.body
  4. Retry — if reproducible, contact AWS with the request ID

Example fix

// before
createAmazonBedrock({ bedrockOptions: { region: 'us-east-1' } }); // modelId typo'd later
// after
const model = bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'); // verify exact model ID & region
const result = await streamText({ model, prompt: 'hi' });
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await streamText({ model, prompt });
} catch (e) {
  if (EmptyResponseBodyError.isInstance(e)) {
    // inspect raw response: status, headers, request id; verify modelId/region
  }
}

Prevention

When it happens

Trigger: Invoking a Bedrock model (streaming) and receiving a response with no body — e.g. wrong model ID/endpoint, invalid request rejected before streaming, or an empty 200 from a proxy.

Common situations: Misconfigured Bedrock runtime endpoint; custom fetch/agent stripping the body; Bedrock returning an error status the handler didn't map; VPC/gateway interference.

Related errors


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