diff --git a/src/api/providers/__tests__/bedrock.spec.ts b/src/api/providers/__tests__/bedrock.spec.ts index 8df495ca9f..76a3ed2e3d 100644 --- a/src/api/providers/__tests__/bedrock.spec.ts +++ b/src/api/providers/__tests__/bedrock.spec.ts @@ -635,11 +635,10 @@ describe("AwsBedrockHandler", () => { expect(mockConverseStreamCommand).toHaveBeenCalled() const commandArg = mockConverseStreamCommand.mock.calls[0][0] as any - // Should include anthropic_beta in additionalModelRequestFields - expect(commandArg.additionalModelRequestFields).toBeDefined() - expect(commandArg.additionalModelRequestFields.anthropic_beta).toEqual(["context-1m-2025-08-07"]) + // Should include anthropic_beta at top level of payload + expect(commandArg.anthropic_beta).toEqual(["context-1m-2025-08-07"]) // Should not include anthropic_version since thinking is not enabled - expect(commandArg.additionalModelRequestFields.anthropic_version).toBeUndefined() + expect(commandArg.anthropic_version).toBeUndefined() }) it("should not include anthropic_beta parameter when 1M context is disabled", async () => { @@ -665,7 +664,9 @@ describe("AwsBedrockHandler", () => { expect(mockConverseStreamCommand).toHaveBeenCalled() const commandArg = mockConverseStreamCommand.mock.calls[0][0] as any - // Should not include anthropic_beta in additionalModelRequestFields + // Should not include anthropic_beta at top level + expect(commandArg.anthropic_beta).toBeUndefined() + // Should not include additionalModelRequestFields when no thinking is enabled expect(commandArg.additionalModelRequestFields).toBeUndefined() }) @@ -693,6 +694,7 @@ describe("AwsBedrockHandler", () => { const commandArg = mockConverseStreamCommand.mock.calls[0][0] as any // Should not include anthropic_beta for non-Sonnet 4 models + expect(commandArg.anthropic_beta).toBeUndefined() expect(commandArg.additionalModelRequestFields).toBeUndefined() }) @@ -740,11 +742,10 @@ describe("AwsBedrockHandler", () => { mockConverseStreamCommand.mock.calls.length - 1 ][0] as any - // Should include anthropic_beta in additionalModelRequestFields - expect(commandArg.additionalModelRequestFields).toBeDefined() - expect(commandArg.additionalModelRequestFields.anthropic_beta).toEqual(["context-1m-2025-08-07"]) + // Should include anthropic_beta at top level of payload + expect(commandArg.anthropic_beta).toEqual(["context-1m-2025-08-07"]) // Should not include anthropic_version since thinking is not enabled - expect(commandArg.additionalModelRequestFields.anthropic_version).toBeUndefined() + expect(commandArg.anthropic_version).toBeUndefined() // Model ID should have cross-region prefix expect(commandArg.modelId).toBe(`us.${BEDROCK_CLAUDE_SONNET_4_MODEL_ID}`) }) diff --git a/src/api/providers/bedrock.ts b/src/api/providers/bedrock.ts index c6a0b35df4..5f2e639302 100644 --- a/src/api/providers/bedrock.ts +++ b/src/api/providers/bedrock.ts @@ -48,13 +48,12 @@ interface BedrockInferenceConfig { } // Define interface for Bedrock additional model request fields -// This includes thinking configuration, 1M context beta, and other model-specific parameters +// This includes thinking configuration and other model-specific parameters interface BedrockAdditionalModelFields { thinking?: { type: "enabled" budget_tokens: number } - anthropic_beta?: string[] [key: string]: any // Add index signature to be compatible with DocumentType } @@ -65,6 +64,7 @@ interface BedrockPayload { system?: SystemContentBlock[] inferenceConfig: BedrockInferenceConfig anthropic_version?: string + anthropic_beta?: string[] additionalModelRequestFields?: BedrockAdditionalModelFields } @@ -383,14 +383,6 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH const baseModelId = this.parseBaseModelId(modelConfig.id) const is1MContextEnabled = baseModelId === BEDROCK_CLAUDE_SONNET_4_MODEL_ID && this.options.awsBedrock1MContext - // Add anthropic_beta for 1M context to additionalModelRequestFields - if (is1MContextEnabled) { - if (!additionalModelRequestFields) { - additionalModelRequestFields = {} as BedrockAdditionalModelFields - } - additionalModelRequestFields.anthropic_beta = ["context-1m-2025-08-07"] - } - const payload: BedrockPayload = { modelId: modelConfig.id, messages: formatted.messages, @@ -399,6 +391,8 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH ...(additionalModelRequestFields && { additionalModelRequestFields }), // Add anthropic_version at top level when using thinking features ...(thinkingEnabled && { anthropic_version: "bedrock-2023-05-31" }), + // Add anthropic_beta at top level when 1M context is enabled + ...(is1MContextEnabled && { anthropic_beta: ["context-1m-2025-08-07"] }), } // Create AbortController with 10 minute timeout