Skip to content

Comments

fix(provider/bedrock): Fix Reasoning - Amazon Bedrock Anthropic#7073

Merged
dancer merged 3 commits intovercel:mainfrom
tleekkul:fix/bedrock/reasoningConfig
Jul 7, 2025
Merged

fix(provider/bedrock): Fix Reasoning - Amazon Bedrock Anthropic#7073
dancer merged 3 commits intovercel:mainfrom
tleekkul:fix/bedrock/reasoningConfig

Conversation

@tleekkul
Copy link
Contributor

@tleekkul tleekkul commented Jul 5, 2025

Background

The Bedrock provider was sending reasoningConfig in the request body when reasoning was enabled, but according to the Bedrock API documentation, the correct field name should be thinking. This caused "Extra inputs are not permitted" errors when using reasoning capabilities with Bedrock models. (#6617)

Summary

  • Fixed field name transformation: Changed reasoningConfig to thinking in additionalModelRequestFields when reasoning is enabled
  • Added filtering logic: Prevented reasoningConfig from being accidentally sent at the top level by filtering it out from providerOptions.bedrock
  • Updated comments: Changed code comments to reflect the correct field name (thinking instead of reasoningConfig)
  • Added comprehensive tests: Added tests for both doGenerate and doStream to verify the transformation works correctly

Verification

Manual Testing. Verified againsts the following examples, which are failing in master branch.

Before Fix

Details
➜  ai-core git:(main) pnpm tsx src/generate-text/amazon-bedrock-reasoning.ts
APICallError [AI_APICallError]: The model returned the following errors: reasoningConfig: Extra inputs are not permitted
    at <anonymous> (/Users/tle/lab/ai/packages/provider-utils/src/response-handler.ts:56:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async postToApi (/Users/tle/lab/ai/packages/provider-utils/src/post-to-api.ts:112:28)
    at async BedrockChatLanguageModel.doGenerate (/Users/tle/lab/ai/packages/amazon-bedrock/src/bedrock-chat-language-model.ts:196:50)
    at async fn (/Users/tle/lab/ai/packages/ai/core/generate-text/generate-text.ts:353:32)
    at async <anonymous> (/Users/tle/lab/ai/packages/ai/core/telemetry/record-span.ts:18:22)
    at async _retryWithExponentialBackoff (/Users/tle/lab/ai/packages/ai/src/util/retry-with-exponential-backoff.ts:36:12)
    at async fn (/Users/tle/lab/ai/packages/ai/core/generate-text/generate-text.ts:309:34)
    at async <anonymous> (/Users/tle/lab/ai/packages/ai/core/telemetry/record-span.ts:18:22)
    at async generateText (/Users/tle/lab/ai/packages/ai/core/generate-text/generate-text.ts:247:12) {
  cause: undefined,
  url: 'https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-3-7-sonnet-20250219-v1%3A0/converse',
  requestBodyValues: {
    system: [],
    messages: [ [Object] ],
    additionalModelRequestFields: { reasoningConfig: [Object] },
    inferenceConfig: { maxOutputTokens: 6144 },
    reasoningConfig: { type: 'enabled', budgetTokens: 2048 }
  },
  statusCode: 400,
  responseHeaders: {
    connection: 'keep-alive',
    'content-length': '102',
    'content-type': 'application/json',
    date: 'Sat, 05 Jul 2025 10:35:36 GMT',
    'x-amzn-errortype': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/',
    'x-amzn-requestid': '<OMITTED>'
  },
  responseBody: '{"message":"The model returned the following errors: reasoningConfig: Extra inputs are not permitted"}',
  isRetryable: false,
  data: {
    message: 'The model returned the following errors: reasoningConfig: Extra inputs are not permitted'
  },
  [Symbol(vercel.ai.error)]: true,
  [Symbol(vercel.ai.error.AI_APICallError)]: true
}

After Fix

generate-text/amazon-bedrock-reasoning-chatbot.ts
➜  ai-core git:(fix/bedrock/reasoningConfig) pnpm tsx src/generate-text/amazon-bedrock-reasoning-chatbot.ts
You: Hello
DefaultStepResult {
  content: [
    {
      type: 'reasoning',
      text: `The user has simply greeted me with "Hello". There is no specific request or question that would require the use of the available weatherTool function. At this point, I should just respond with a friendly greeting and possibly indicate that I'm here to help.`,
      providerMetadata: [Object]
    },
    {
      type: 'text',
      text: "Hello! How can I help you today? I'm here to assist you with information, answer questions, or help with various tasks. Is there something specific you'd like to know or discuss?"
    }
  ],
  finishReason: 'stop',
  usage: {
    inputTokens: 455,
    outputTokens: 104,
    totalTokens: 559,
    cachedInputTokens: 0
  },
  warnings: [],
  request: {},
  response: {
    id: 'aitxt-uvy3GgPrVyR7uWaoY6AgHkch',
    timestamp: 2025-07-05T10:37:19.527Z,
    modelId: 'us.anthropic.claude-3-7-sonnet-20250219-v1:0',
    headers: {
      connection: 'keep-alive',
      'content-length': '1051',
      'content-type': 'application/json',
      date: 'Sat, 05 Jul 2025 10:37:19 GMT',
      'x-amzn-requestid': 'OMITTED'
    },
    body: undefined,
    messages: [ [Object] ]
  },
  providerMetadata: { bedrock: { usage: [Object] } }
}
The user has simply greeted me with "Hello". There is no specific request or question that would require the use of the available weatherTool function. At this point, I should just respond with a friendly greeting and possibly indicate that I'm here to help.
Hello! How can I help you today? I'm here to assist you with information, answer questions, or help with various tasks. Is there something specific you'd like to know or discuss?
generate-text/amazon-bedrock-reasoning.ts
➜  ai-core git:(fix/bedrock/reasoningConfig) pnpm tsx src/generate-text/amazon-bedrock-reasoning.ts
Reasoning:
[
  {
    type: 'reasoning',
    text: 'Let me count the number of "r"s in the word "strawberry".\n' +
      '\n' +
      'The word "strawberry" is spelled:\n' +
      's-t-r-a-w-b-e-r-r-y\n' +
      '\n' +
      'Going through each letter:\n' +
      '- "s": not an "r"\n' +
      '- "t": not an "r"\n' +
      '- "r": this is an "r" (first one)\n' +
      '- "a": not an "r"\n' +
      '- "w": not an "r"\n' +
      '- "b": not an "r"\n' +
      '- "e": not an "r"\n' +
      '- "r": this is an "r" (second one)\n' +
      '- "r": this is an "r" (third one)\n' +
      '- "y": not an "r"\n' +
      '\n' +
      'So there are 3 occurrences of the letter "r" in the word "strawberry".',
    providerMetadata: { bedrock: [Object] }
  }
]

Text:
There are 3 "r"s in the word "strawberry".

Warnings: [
  {
    type: 'unsupported-setting',
    setting: 'temperature',
    details: 'temperature is not supported when thinking is enabled'
  }
]
stream-text/amazon-bedrock-reasoning-chatbot.ts
➜  ai-core git:(fix/bedrock/reasoningConfig) pnpm tsx src/stream-text/amazon-bedrock-reasoning-chatbot.ts
You: Hello

Assistant: URL https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-3-7-sonnet-20250219-v1%3A0/converse-stream
Headers {
  "content-type": "application/json",
  "authorization": "<OMITTED>",
  "x-amz-date": "20250705T103848Z",
  "x-amz-security-token": "<OMITTED>"
}
Body {
  "system": [],
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "text": "Hello"
        }
      ]
    }
  ],
  "additionalModelRequestFields": {
    "thinking": {
      "type": "enabled",
      "budget_tokens": 2048
    }
  },
  "inferenceConfig": {
    "maxOutputTokens": 6144
  },
  "toolConfig": {
    "tools": [
      {
        "toolSpec": {
          "name": "weather",
          "description": "Get the weather in a location",
          "inputSchema": {
            "json": {
              "$schema": "http://json-schema.org/draft-07/schema#",
              "type": "object",
              "properties": {
                "location": {
                  "description": "The location to get the weather for",
                  "type": "string"
                }
              },
              "required": [
                "location"
              ],
              "additionalProperties": false
            }
          }
        }
      }
    ],
    "toolChoice": {
      "auto": {}
    }
  }
}
> The user has just greeted me with "Hello". This is a general greeting and doesn't contain any specific request that would require using the available tools. The only tool available to me is the "weather" function, which requires a location parameter to provide weather information.

Since the user hasn't asked about weather or mentioned any location, I don't need to use any tools at this point. I should simply respond with a greeting and perhaps let them know what I can help with, particularly mentioning that I can provide weather information since that's the capability I have.Hello! How can I help you today? I can provide information such as checking the weather for a specific location. Is there something specific you'd like to know?

You:
stream-text/amazon-bedrock-reasoning-fullstream.ts
➜  ai-core git:(fix/bedrock/reasoningConfig) pnpm tsx src/stream-text/amazon-bedrock-reasoning-fullstream.ts

REASONING:

The user is asking about the weather in San Francisco. I have a weather function available that takes a location parameter. San Francisco is a valid location, so I can call this function to get the weather information.

Required parameter:
- location: "San Francisco"

All required parameters are available, so I can proceed with the function call.
TEXT:

I'll check the current weather in San Francisco for you.
Tool call: 'weather' {"location":"San Francisco"}
Tool response: 'weather' {"location":"San Francisco","temperature":75}The current temperature in San Francisco is 75 degrees Fahrenheit.% 
stream-text/amazon-bedrock-reasoning.ts
➜  ai-core git:(fix/bedrock/reasoningConfig) pnpm tsx src/stream-text/amazon-bedrock-reasoning.ts
To answer this question, I need to count the number of times the letter "r" appears in the word "strawberry".

Let me go through the word letter by letter:
s - not an "r"
t - not an "r"
r - this is an "r"
a - not an "r"
w - not an "r"
b - not an "r"
e - not an "r"
r - this is an "r"
r - this is an "r"
y - not an "r"

So I count 3 instances of the letter "r" in the word "strawberry".There are 3 letter "r"s in the word "strawberry".
Warnings: [
  {
    type: 'unsupported-setting',
    setting: 'temperature',
    details: 'temperature is not supported when thinking is enabled'
  }
]

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Related Issues

Fixes #6617

aryuthc added 3 commits July 5, 2025 17:20
…ield for Bedrock API

- Change reasoningConfig field name to "thinking" in additionalModelRequestFields
- Filter out reasoningConfig from providerOptions.bedrock to prevent API errors
- Add tests to verify reasoningConfig transformation works for both generate and stream
- Fixes "Extra inputs are not permitted" error when using reasoning with Bedrock
@lgrammel lgrammel requested a review from dancer July 7, 2025 13:36
@dancer dancer merged commit a10bf62 into vercel:main Jul 7, 2025
10 of 11 checks passed
@rfsmart-eland
Copy link

Is it possible to get this released in the v4 / v2 Bedrock provider and not just the v5 / v3-beta Bedrock provider?

As is, the bug this fixes exists in v2.2.11 (current) of the Bedrock provider.

@tleekkul tleekkul deleted the fix/bedrock/reasoningConfig branch July 9, 2025 08:52
@gr2m gr2m added ai/provider provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reasoning is not working - Amazon Bedrock Anthropic

5 participants