-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Description
The @ai-sdk/amazon-bedrock package has a parameter naming bug that causes validation errors when using reasoning effort with OpenAI and possibly other non-Anthropic models (e.g., GPT-OSS models on AWS Bedrock).
The Problem
When setting reasoning effort for OpenAI models, the SDK sends reasoningConfig (camelCase) to AWS Bedrock, but the API expects reasoning_effort (snake_case).
Error message:
{
"code": "validation_error",
"message": "Failed to deserialize the JSON body into the target type: unknown variant 'reasoningConfig', expected one of 'audio', 'frequency_penalty', ..., 'reasoning_effort', ...",
"type": "invalid_request_error"
}
Root Cause
Location: node_modules/@ai-sdk/amazon-bedrock/dist/index.mjs:795-807
The bug was introduced in v3.0.66 with the feature "Support Nova 2 extended reasoning 'maxReasoningEffort' field".
For non-Anthropic models, the code does:
const maxReasoningEffort = bedrockOptions.reasoningConfig?.maxReasoningEffort;
if (maxReasoningEffort != null && !isAnthropicModel) {
return {
...bedrockOptions.additionalModelRequestFields,
reasoningConfig: { // BUG: Should be reasoning_effort
maxReasoningEffort: maxReasoningEffort
}
};
}Reproduction Steps
- Initialize a OpenAI model (e.g., GPT-OSS) with reasoning configuration:
import { bedrock } from '@ai-sdk/amazon-bedrock';
const model = bedrock('openai.gpt-oss-120b-1:0', {
reasoningConfig: {
type: 'enabled',
maxReasoningEffort: 'medium'
}
});- Call the model
- Observe validation error from AWS Bedrock API
Expected Behavior
The SDK should send reasoning_effort: 'medium' (snake_case) to AWS Bedrock for OpenAI and possibly other non-Anthropic models.
Actual Behavior
The SDK sends reasoningConfig: { maxReasoningEffort: 'medium' } (camelCase nested object), which AWS Bedrock rejects.
Current Status
- ✅ Anthropic models work correctly - they use
thinking.budget_tokens - ❌ OpenAI and possibly other non-Anthropic models fail - they incorrectly use
reasoningConfig
Workaround
Use additionalModelRequestFields to bypass the SDK's reasoning configuration:
const model = bedrock('openai.gpt-oss-120b-1:0', {
additionalModelRequestFields: {
reasoning_effort: 'medium' // Send snake_case directly
}
});Suggested Fix
For OpenAI and possibly other non-Anthropic models, the SDK should send the raw reasoning_effort value directly with snake_case naming:
if (maxReasoningEffort != null && !isAnthropicModel) {
return {
...bedrockOptions.additionalModelRequestFields,
reasoning_effort: maxReasoningEffort // Fix: Use snake_case parameter name
};
}AI SDK Version
- @ai-sdk/amazon-bedrock: 3.0.72 (latest as of 2024-12-30)
Code of Conduct
- I agree to follow this project's Code of Conduct