🪨 feat: Anthropic Beta Support for Bedrock (#11371)

* 🪨 feat: Anthropic Beta Support for Bedrock

- Updated the Bedrock input parser to dynamically generate `anthropic_beta` headers based on the model identifier.
- Added a new utility function `getBedrockAnthropicBetaHeaders` to determine applicable headers for various Anthropic models.
- Modified existing tests to reflect changes in expected `anthropic_beta` values, including new test cases for full model IDs.

* test: Update Bedrock Input Parser Tests for Beta Headers

- Modified the test case for explicit thinking configuration to reflect the addition of `anthropic_beta` headers.
- Ensured that the test now verifies the presence of specific beta header values in the additional model request fields.
This commit is contained in:
Danny Avila 2026-01-15 22:48:48 -05:00 committed by GitHub
parent 476882455e
commit 81f4af55b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 75 additions and 12 deletions

View file

@ -14,7 +14,7 @@ describe('bedrockInputParser', () => {
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
});
test('should match anthropic.claude-sonnet-4 model', () => {
test('should match anthropic.claude-sonnet-4 model with 1M context header', () => {
const input = {
model: 'anthropic.claude-sonnet-4',
};
@ -22,10 +22,13 @@ describe('bedrockInputParser', () => {
const additionalFields = result.additionalModelRequestFields as Record<string, unknown>;
expect(additionalFields.thinking).toBe(true);
expect(additionalFields.thinkingBudget).toBe(2000);
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
expect(additionalFields.anthropic_beta).toEqual([
'output-128k-2025-02-19',
'context-1m-2025-08-07',
]);
});
test('should match anthropic.claude-opus-5 model', () => {
test('should match anthropic.claude-opus-5 model without 1M context header', () => {
const input = {
model: 'anthropic.claude-opus-5',
};
@ -36,7 +39,7 @@ describe('bedrockInputParser', () => {
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
});
test('should match anthropic.claude-haiku-6 model', () => {
test('should match anthropic.claude-haiku-6 model without 1M context header', () => {
const input = {
model: 'anthropic.claude-haiku-6',
};
@ -47,7 +50,7 @@ describe('bedrockInputParser', () => {
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
});
test('should match anthropic.claude-4-sonnet model', () => {
test('should match anthropic.claude-4-sonnet model with 1M context header', () => {
const input = {
model: 'anthropic.claude-4-sonnet',
};
@ -55,10 +58,13 @@ describe('bedrockInputParser', () => {
const additionalFields = result.additionalModelRequestFields as Record<string, unknown>;
expect(additionalFields.thinking).toBe(true);
expect(additionalFields.thinkingBudget).toBe(2000);
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
expect(additionalFields.anthropic_beta).toEqual([
'output-128k-2025-02-19',
'context-1m-2025-08-07',
]);
});
test('should match anthropic.claude-4.5-sonnet model', () => {
test('should match anthropic.claude-4.5-sonnet model with 1M context header', () => {
const input = {
model: 'anthropic.claude-4.5-sonnet',
};
@ -66,10 +72,13 @@ describe('bedrockInputParser', () => {
const additionalFields = result.additionalModelRequestFields as Record<string, unknown>;
expect(additionalFields.thinking).toBe(true);
expect(additionalFields.thinkingBudget).toBe(2000);
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
expect(additionalFields.anthropic_beta).toEqual([
'output-128k-2025-02-19',
'context-1m-2025-08-07',
]);
});
test('should match anthropic.claude-4-7-sonnet model', () => {
test('should match anthropic.claude-4-7-sonnet model with 1M context header', () => {
const input = {
model: 'anthropic.claude-4-7-sonnet',
};
@ -77,7 +86,24 @@ describe('bedrockInputParser', () => {
const additionalFields = result.additionalModelRequestFields as Record<string, unknown>;
expect(additionalFields.thinking).toBe(true);
expect(additionalFields.thinkingBudget).toBe(2000);
expect(additionalFields.anthropic_beta).toEqual(['output-128k-2025-02-19']);
expect(additionalFields.anthropic_beta).toEqual([
'output-128k-2025-02-19',
'context-1m-2025-08-07',
]);
});
test('should match anthropic.claude-sonnet-4-20250514-v1:0 with full model ID', () => {
const input = {
model: 'anthropic.claude-sonnet-4-20250514-v1:0',
};
const result = bedrockInputParser.parse(input) as BedrockConverseInput;
const additionalFields = result.additionalModelRequestFields as Record<string, unknown>;
expect(additionalFields.thinking).toBe(true);
expect(additionalFields.thinkingBudget).toBe(2000);
expect(additionalFields.anthropic_beta).toEqual([
'output-128k-2025-02-19',
'context-1m-2025-08-07',
]);
});
test('should not match non-Claude models', () => {
@ -110,7 +136,7 @@ describe('bedrockInputParser', () => {
expect(additionalFields?.anthropic_beta).toBeUndefined();
});
test('should respect explicit thinking configuration', () => {
test('should respect explicit thinking configuration but still add beta headers', () => {
const input = {
model: 'anthropic.claude-sonnet-4',
thinking: false,
@ -119,6 +145,10 @@ describe('bedrockInputParser', () => {
const additionalFields = result.additionalModelRequestFields as Record<string, unknown>;
expect(additionalFields.thinking).toBeUndefined();
expect(additionalFields.thinkingBudget).toBeUndefined();
expect(additionalFields.anthropic_beta).toEqual([
'output-128k-2025-02-19',
'context-1m-2025-08-07',
]);
});
test('should respect custom thinking budget', () => {