{"record":{"id":"23d652973788255e","repo":"vercel/ai","slug":"ai-emptyresponsebodyerror","errorCode":"AI_EmptyResponseBodyError","errorMessage":"Empty response body","messagePattern":"Empty response body","errorType":"exception","errorClass":"EmptyResponseBodyError","httpStatus":null,"severity":"error","filePath":"packages/amazon-bedrock/src/amazon-bedrock-event-stream-response-handler.ts","lineNumber":20,"sourceCode":"import {\n  safeParseJSON,\n  extractResponseHeaders,\n  safeValidateTypes,\n  type ParseResult,\n  type ResponseHandler,\n} from '@ai-sdk/provider-utils';\nimport type { ZodType } from 'zod/v4';\nimport { createAmazonBedrockEventStreamDecoder } from './amazon-bedrock-event-stream-decoder';\n\nexport const createAmazonBedrockEventStreamResponseHandler =\n  <T>(\n    chunkSchema: ZodType<T, any>,\n  ): ResponseHandler<ReadableStream<ParseResult<T>>> =>\n  async ({ response }: { response: Response }) => {\n    const responseHeaders = extractResponseHeaders(response);\n\n    if (response.body == null) {\n      throw new EmptyResponseBodyError({});\n    }\n\n    return {\n      responseHeaders,\n      value: createAmazonBedrockEventStreamDecoder<ParseResult<T>>(\n        response.body,\n        async (event, controller) => {\n          const payloadType =\n            event.messageType === 'event'\n              ? event.eventType\n              : event.messageType === 'exception'\n                ? event.exceptionType\n                : undefined;\n\n          if (payloadType == null) {\n            return;\n          }\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/amazon-bedrock/src/amazon-bedrock-event-stream-response-handler.ts#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"Misconfigured Bedrock runtime endpoint; custom fetch/agent stripping the body; Bedrock returning an error status the handler didn't map; VPC/gateway interference.","solutions":["Verify the modelId and region are correct and the model is enabled for your account","Log the raw response status/headers to see what Bedrock actually returned","Remove any custom fetch wrapper that could consume or drop response.body","Retry — if reproducible, contact AWS with the request ID"],"exampleFix":"// before\ncreateAmazonBedrock({ bedrockOptions: { region: 'us-east-1' } }); // modelId typo'd later\n// after\nconst model = bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'); // verify exact model ID & region\nconst result = await streamText({ model, prompt: 'hi' });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await streamText({ model, prompt });\n} catch (e) {\n  if (EmptyResponseBodyError.isInstance(e)) {\n    // inspect raw response: status, headers, request id; verify modelId/region\n  }\n}","preventionTips":["Verify modelId and region before invoking","Don't wrap fetch with agents that strip response bodies","Log raw responses when debugging provider connectivity"],"tags":["bedrock","streaming","empty-response"],"backgroundTag":"empty-response-body","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}