Skip to content

Amazon Bedrock + streamText + maxSteps often leads to APICallError #6254

@MaxAller

Description

@MaxAller

Description

When using the Amazon Bedrock provider (v2.2.8), along with streamText and a high-ish (~20) value for maxSteps, it's not uncommon to run into an error like the following around half the time:

APICallError [AI_APICallError]: undefined: The text field in the ContentBlock object at messages.7.content.0 is blank. Add text to the text field, and try again.
    at file:///<snip>/lib/node_modules/@ai-sdk/amazon-bedrock/node_modules/@ai-sdk/provider-utils/dist/index.mjs:667:14
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async postToApi (file:///<snip>/lib/node_modules/@ai-sdk/amazon-bedrock/node_modules/@ai-sdk/provider-utils/dist/index.mjs:567:28)
    at async BedrockChatLanguageModel.doStream (file:///<snip>/lib/node_modules/@ai-sdk/amazon-bedrock/dist/index.mjs:740:50)
    at async fn (file://///<snip>/node_modules/ai/dist/index.mjs:5622:25)
    at async file://///<snip>/node_modules/ai/dist/index.mjs:470:22
    at async _retryWithExponentialBackoff (file://///<snip>/node_modules/ai/dist/index.mjs:271:12)
    at async streamStep (file://///<snip>/node_modules/ai/dist/index.mjs:5577:15)

It also dumps out the messages in question:

    messages: [
      // irrelevant messages omitted for brevity
      {
        role: 'assistant',
        content: [
          {
            text: '\n' +
              '\n' +
              "Let's also check the <snip> to see if there are any issues there:"
          },
          { toolUse: [Object] }
        ]
      },
      { role: 'user', content: [ { toolResult: [Object] } ] },
      {
        // >>> This appears to be the message that's breaking the API, messages.7
        role: 'assistant',
        content: [ { text: '\n\n' }, { toolUse: [Object] } ]
      },
      { role: 'user', content: [ { toolResult: [Object] } ] }
    ],

In particular, it seems not to like this content block: { text: '\n\n' }.

I don't have specific repro steps, but it seems to happen somewhat consistently for higher maxSteps, as mentioned earlier.

Also, using Claude Sonnet 3.7, reasoning not enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/amazon-bedrockIssues related to the @ai-sdk/amazon-bedrock provider

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions