Skip to content

Bug: Bedrock Anthropic reasoning does not work when using additionalModelRequestFields #9312

@ci

Description

@ci

Description

With additionalModelRequestFields set, reasoning doesn't work anymore.

In a10bf62 - filtering out reasoningConfig was added, but that leaves potential additionalModelRequestFields in, which overwrites the additionalModelRequestFields that includes the reasoningConfig.

Repro:

import { bedrock } from "@ai-sdk/amazon-bedrock";
import { stepCountIs, streamText } from "ai";
import "dotenv/config";

async function main() {
  const result = streamText({
    model: bedrock("us.anthropic.claude-3-7-sonnet-20250219-v1:0"),
    prompt: 'How many "r"s are in the word "strawberry"?',
    onError: (error) => console.error(error),
    providerOptions: {
      bedrock: {
        reasoningConfig: { type: "enabled", budgetTokens: 1024 },
        // removing this line below makes reasoning work again
        additionalModelRequestFields: {},
      },
    },
    maxRetries: 0,
    stopWhen: stepCountIs(5),
  });

  for await (const part of result.fullStream) {
    if (part.type === "reasoning-delta") {
      process.stdout.write("\x1b[34m" + part.text + "\x1b[0m");
    } else if (part.type === "text-delta") {
      process.stdout.write(part.text);
    }
  }

  console.log();
  console.log("Warnings:", await result.warnings);
}

main().catch(console.error);

AI SDK Version

"@ai-sdk/amazon-bedrock": "^4.0.0-beta.18",
"ai": "^6.0.0-beta.31"

also happens on

"@ai-sdk/amazon-bedrock": "^3.0.31",
"ai": "^5.0.61"

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions