Skip to content

Commit ed6bf41

Browse files
committed
fix: move anthropic_beta back to top level for AWS Bedrock 1M context
Fixes #7085 - "invalid beta flag" error when using 1M context with Claude Sonnet 4 The anthropic_beta parameter needs to be at the top level of the Bedrock payload, not inside additionalModelRequestFields. This reverts the incorrect placement introduced in PR #7056 while keeping the other improvements from that PR.
1 parent dcbb7a6 commit ed6bf41

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/api/providers/__tests__/bedrock.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,10 @@ describe("AwsBedrockHandler", () => {
635635
expect(mockConverseStreamCommand).toHaveBeenCalled()
636636
const commandArg = mockConverseStreamCommand.mock.calls[0][0] as any
637637

638-
// Should include anthropic_beta in additionalModelRequestFields
639-
expect(commandArg.additionalModelRequestFields).toBeDefined()
640-
expect(commandArg.additionalModelRequestFields.anthropic_beta).toEqual(["context-1m-2025-08-07"])
638+
// Should include anthropic_beta at top level of payload
639+
expect(commandArg.anthropic_beta).toEqual(["context-1m-2025-08-07"])
641640
// Should not include anthropic_version since thinking is not enabled
642-
expect(commandArg.additionalModelRequestFields.anthropic_version).toBeUndefined()
641+
expect(commandArg.anthropic_version).toBeUndefined()
643642
})
644643

645644
it("should not include anthropic_beta parameter when 1M context is disabled", async () => {
@@ -665,7 +664,9 @@ describe("AwsBedrockHandler", () => {
665664
expect(mockConverseStreamCommand).toHaveBeenCalled()
666665
const commandArg = mockConverseStreamCommand.mock.calls[0][0] as any
667666

668-
// Should not include anthropic_beta in additionalModelRequestFields
667+
// Should not include anthropic_beta at top level
668+
expect(commandArg.anthropic_beta).toBeUndefined()
669+
// Should not include additionalModelRequestFields when no thinking is enabled
669670
expect(commandArg.additionalModelRequestFields).toBeUndefined()
670671
})
671672

@@ -693,6 +694,7 @@ describe("AwsBedrockHandler", () => {
693694
const commandArg = mockConverseStreamCommand.mock.calls[0][0] as any
694695

695696
// Should not include anthropic_beta for non-Sonnet 4 models
697+
expect(commandArg.anthropic_beta).toBeUndefined()
696698
expect(commandArg.additionalModelRequestFields).toBeUndefined()
697699
})
698700

@@ -740,11 +742,10 @@ describe("AwsBedrockHandler", () => {
740742
mockConverseStreamCommand.mock.calls.length - 1
741743
][0] as any
742744

743-
// Should include anthropic_beta in additionalModelRequestFields
744-
expect(commandArg.additionalModelRequestFields).toBeDefined()
745-
expect(commandArg.additionalModelRequestFields.anthropic_beta).toEqual(["context-1m-2025-08-07"])
745+
// Should include anthropic_beta at top level of payload
746+
expect(commandArg.anthropic_beta).toEqual(["context-1m-2025-08-07"])
746747
// Should not include anthropic_version since thinking is not enabled
747-
expect(commandArg.additionalModelRequestFields.anthropic_version).toBeUndefined()
748+
expect(commandArg.anthropic_version).toBeUndefined()
748749
// Model ID should have cross-region prefix
749750
expect(commandArg.modelId).toBe(`us.${BEDROCK_CLAUDE_SONNET_4_MODEL_ID}`)
750751
})

src/api/providers/bedrock.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ interface BedrockInferenceConfig {
4848
}
4949

5050
// Define interface for Bedrock additional model request fields
51-
// This includes thinking configuration, 1M context beta, and other model-specific parameters
51+
// This includes thinking configuration and other model-specific parameters
5252
interface BedrockAdditionalModelFields {
5353
thinking?: {
5454
type: "enabled"
5555
budget_tokens: number
5656
}
57-
anthropic_beta?: string[]
5857
[key: string]: any // Add index signature to be compatible with DocumentType
5958
}
6059

@@ -65,6 +64,7 @@ interface BedrockPayload {
6564
system?: SystemContentBlock[]
6665
inferenceConfig: BedrockInferenceConfig
6766
anthropic_version?: string
67+
anthropic_beta?: string[]
6868
additionalModelRequestFields?: BedrockAdditionalModelFields
6969
}
7070

@@ -383,14 +383,6 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
383383
const baseModelId = this.parseBaseModelId(modelConfig.id)
384384
const is1MContextEnabled = baseModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID && this.options.awsBedrock1MContext
385385

386-
// Add anthropic_beta for 1M context to additionalModelRequestFields
387-
if (is1MContextEnabled) {
388-
if (!additionalModelRequestFields) {
389-
additionalModelRequestFields = {} as BedrockAdditionalModelFields
390-
}
391-
additionalModelRequestFields.anthropic_beta = ["context-1m-2025-08-07"]
392-
}
393-
394386
const payload: BedrockPayload = {
395387
modelId: modelConfig.id,
396388
messages: formatted.messages,
@@ -399,6 +391,8 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
399391
...(additionalModelRequestFields && { additionalModelRequestFields }),
400392
// Add anthropic_version at top level when using thinking features
401393
...(thinkingEnabled && { anthropic_version: "bedrock-2023-05-31" }),
394+
// Add anthropic_beta at top level when 1M context is enabled
395+
...(is1MContextEnabled && { anthropic_beta: ["context-1m-2025-08-07"] }),
402396
}
403397

404398
// Create AbortController with 10 minute timeout

0 commit comments

Comments
 (0)