vercel/ai · error · Error

Incomplete Amazon Bedrock event-stream frame: ${buffer.lengt

Error message

Incomplete Amazon Bedrock event-stream frame: ${buffer.length} buffered bytes remain at end of stream.

What it means

Bedrock's event-stream protocol frames carry explicit total lengths; the decoder buffers bytes until a complete frame arrives. If the stream ends while bytes are still buffered, the frame was truncated, so flush() throws rather than parsing a partial event. This indicates a broken/interrupted connection or a malformed upstream stream.

Source

Thrown at packages/amazon-bedrock/src/amazon-bedrock-event-stream-decoder.ts:63

          const messageType = decoded.headers[':message-type']?.value as string;
          const eventType = decoded.headers[':event-type']?.value as
            | string
            | undefined;
          const exceptionType = decoded.headers[':exception-type']?.value as
            | string
            | undefined;
          const data = textDecoder.decode(decoded.body);

          await processEvent(
            { messageType, eventType, exceptionType, data },
            controller,
          );
        }
      },
      flush() {
        if (buffer.length > 0) {
          throw new Error(
            `Incomplete Amazon Bedrock event-stream frame: ${buffer.length} buffered bytes remain at end of stream.`,
          );
        }
      },
    }),
  );
}

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Retry the request — transient network truncation is usually resolved by re-invoking the model
  2. Check proxies/load balancers for idle/read timeouts and raise them for streaming responses
  3. Ensure you are not consuming response.body through another transformation that drops trailing chunks
  4. Update @ai-sdk/amazon-bedrock; if persistent, capture the request ID from response headers and report to AWS support

Example fix

// before
const result = await streamText({ model, prompt }); // one shot, no retry
// after
const result = await retry(
  () => streamText({ model, prompt }),
  { attempts: 3, on: /Incomplete Amazon Bedrock event-stream frame/ }
);
Defensive patterns

Strategy: retry

Try / catch

try {
  return await streamText({ model, prompt });
} catch (e) {
  if (e instanceof Error && e.message.includes('Incomplete Amazon Bedrock event-stream frame')) {
    return await streamText({ model, prompt }); // retry with backoff
  }
  throw e;
}

Prevention

When it happens

Trigger: The HTTP response body from Bedrock's InvokeModelWithResponseStream ends mid-frame — network interruption, proxy/load-balancer timeout cutting the connection, or an intermediary that altered chunk boundaries.

Common situations: Long-running streams killed by an ALB/API gateway idle timeout; streaming through a corporate proxy that buffers and truncates; mobile/unstable networks dropping the connection mid-response.

Related errors


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