From 28270bec58a24c218141378887ce62e9f407724e Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 12 Jan 2026 19:12:36 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B5=20chore:=20Remove=20deprecated=20'?= =?UTF-8?q?prompt-caching'=20Anthropic=20header=20(#11313)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/translations/anthropic.ts | 3 -- .../api/src/endpoints/anthropic/helpers.ts | 21 +++------- .../api/src/endpoints/anthropic/llm.spec.ts | 42 +++++++------------ .../api/src/endpoints/anthropic/vertex.ts | 2 +- .../endpoints/openai/config.anthropic.spec.ts | 27 +++--------- 5 files changed, 27 insertions(+), 68 deletions(-) diff --git a/config/translations/anthropic.ts b/config/translations/anthropic.ts index a31c45ffed..968474a45a 100644 --- a/config/translations/anthropic.ts +++ b/config/translations/anthropic.ts @@ -10,9 +10,6 @@ export function getClient() { /** @type {Anthropic.default.RequestOptions} */ const options = { apiKey: process.env.ANTHROPIC_API_KEY, - defaultHeaders: { - 'anthropic-beta': 'prompt-caching-2024-07-31', - }, }; return new Anthropic(options); diff --git a/packages/api/src/endpoints/anthropic/helpers.ts b/packages/api/src/endpoints/anthropic/helpers.ts index ae199ce89b..0596c1efcc 100644 --- a/packages/api/src/endpoints/anthropic/helpers.ts +++ b/packages/api/src/endpoints/anthropic/helpers.ts @@ -42,30 +42,19 @@ function getClaudeHeaders( if (/claude-3[-.]5-sonnet/.test(model)) { return { - 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15,prompt-caching-2024-07-31', + 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15', }; } else if (/claude-3[-.]7/.test(model)) { return { - 'anthropic-beta': - 'token-efficient-tools-2025-02-19,output-128k-2025-02-19,prompt-caching-2024-07-31', + 'anthropic-beta': 'token-efficient-tools-2025-02-19,output-128k-2025-02-19', }; } else if (/claude-sonnet-4/.test(model)) { return { - 'anthropic-beta': 'prompt-caching-2024-07-31,context-1m-2025-08-07', - }; - } else if ( - /claude-(?:sonnet|opus|haiku)-[4-9]/.test(model) || - /claude-[4-9]-(?:sonnet|opus|haiku)?/.test(model) || - /claude-4(?:-(?:sonnet|opus|haiku))?/.test(model) - ) { - return { - 'anthropic-beta': 'prompt-caching-2024-07-31', - }; - } else { - return { - 'anthropic-beta': 'prompt-caching-2024-07-31', + 'anthropic-beta': 'context-1m-2025-08-07', }; } + + return undefined; } /** diff --git a/packages/api/src/endpoints/anthropic/llm.spec.ts b/packages/api/src/endpoints/anthropic/llm.spec.ts index 5c220d2dc7..0e457b60c2 100644 --- a/packages/api/src/endpoints/anthropic/llm.spec.ts +++ b/packages/api/src/endpoints/anthropic/llm.spec.ts @@ -87,7 +87,7 @@ describe('getLLMConfig', () => { expect(result.llmConfig.thinking).toHaveProperty('budget_tokens', 2000); }); - it('should add "prompt-caching" and "context-1m" beta headers for claude-sonnet-4 model', () => { + it('should add "context-1m" beta header for claude-sonnet-4 model', () => { const modelOptions = { model: 'claude-sonnet-4-20250514', promptCache: true, @@ -97,12 +97,10 @@ describe('getLLMConfig', () => { expect(clientOptions?.defaultHeaders).toBeDefined(); expect(clientOptions?.defaultHeaders).toHaveProperty('anthropic-beta'); const defaultHeaders = clientOptions?.defaultHeaders as Record; - expect(defaultHeaders['anthropic-beta']).toBe( - 'prompt-caching-2024-07-31,context-1m-2025-08-07', - ); + expect(defaultHeaders['anthropic-beta']).toBe('context-1m-2025-08-07'); }); - it('should add "prompt-caching" and "context-1m" beta headers for claude-sonnet-4 model formats', () => { + it('should add "context-1m" beta header for claude-sonnet-4 model formats', () => { const modelVariations = [ 'claude-sonnet-4-20250514', 'claude-sonnet-4-latest', @@ -116,26 +114,21 @@ describe('getLLMConfig', () => { expect(clientOptions?.defaultHeaders).toBeDefined(); expect(clientOptions?.defaultHeaders).toHaveProperty('anthropic-beta'); const defaultHeaders = clientOptions?.defaultHeaders as Record; - expect(defaultHeaders['anthropic-beta']).toBe( - 'prompt-caching-2024-07-31,context-1m-2025-08-07', - ); + expect(defaultHeaders['anthropic-beta']).toBe('context-1m-2025-08-07'); }); }); - it('should add "prompt-caching" beta header for claude-opus-4-5 model', () => { + it('should not add beta headers for claude-opus-4-5 model (prompt caching no longer needs header)', () => { const modelOptions = { model: 'claude-opus-4-5', promptCache: true, }; const result = getLLMConfig('test-key', { modelOptions }); const clientOptions = result.llmConfig.clientOptions; - expect(clientOptions?.defaultHeaders).toBeDefined(); - expect(clientOptions?.defaultHeaders).toHaveProperty('anthropic-beta'); - const defaultHeaders = clientOptions?.defaultHeaders as Record; - expect(defaultHeaders['anthropic-beta']).toBe('prompt-caching-2024-07-31'); + expect(clientOptions?.defaultHeaders).toBeUndefined(); }); - it('should add "prompt-caching" beta header for claude-opus-4-5 model formats', () => { + it('should not add beta headers for claude-opus-4-5 model formats (prompt caching no longer needs header)', () => { const modelVariations = [ 'claude-opus-4-5', 'claude-opus-4-5-20250420', @@ -147,10 +140,7 @@ describe('getLLMConfig', () => { const modelOptions = { model, promptCache: true }; const result = getLLMConfig('test-key', { modelOptions }); const clientOptions = result.llmConfig.clientOptions; - expect(clientOptions?.defaultHeaders).toBeDefined(); - expect(clientOptions?.defaultHeaders).toHaveProperty('anthropic-beta'); - const defaultHeaders = clientOptions?.defaultHeaders as Record; - expect(defaultHeaders['anthropic-beta']).toBe('prompt-caching-2024-07-31'); + expect(clientOptions?.defaultHeaders).toBeUndefined(); }); }); @@ -309,9 +299,9 @@ describe('getLLMConfig', () => { }, }); - // claude-3-5-sonnet supports prompt caching and should get the appropriate headers + // claude-3-5-sonnet supports prompt caching and should get the max-tokens header expect(result.llmConfig.clientOptions?.defaultHeaders).toEqual({ - 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15,prompt-caching-2024-07-31', + 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15', }); }); @@ -520,8 +510,7 @@ describe('getLLMConfig', () => { expect(result.llmConfig).not.toHaveProperty('topK'); // Should have appropriate headers for Claude-3.7 with prompt cache expect(result.llmConfig.clientOptions?.defaultHeaders).toEqual({ - 'anthropic-beta': - 'token-efficient-tools-2025-02-19,output-128k-2025-02-19,prompt-caching-2024-07-31', + 'anthropic-beta': 'token-efficient-tools-2025-02-19,output-128k-2025-02-19', }); }); @@ -1170,13 +1159,14 @@ describe('getLLMConfig', () => { it('should handle prompt cache support logic for different models', () => { const testCases = [ - // Models that support prompt cache + // Models that support prompt cache (and have other beta headers) { model: 'claude-3-5-sonnet', promptCache: true, shouldHaveHeaders: true }, { model: 'claude-3.5-sonnet-20241022', promptCache: true, shouldHaveHeaders: true }, { model: 'claude-3-7-sonnet', promptCache: true, shouldHaveHeaders: true }, { model: 'claude-3.7-sonnet-20250109', promptCache: true, shouldHaveHeaders: true }, - { model: 'claude-3-opus', promptCache: true, shouldHaveHeaders: true }, { model: 'claude-sonnet-4-20250514', promptCache: true, shouldHaveHeaders: true }, + // Models that support prompt cache but have no additional beta headers needed + { model: 'claude-3-opus', promptCache: true, shouldHaveHeaders: false }, // Models that don't support prompt cache { model: 'claude-3-5-sonnet-latest', promptCache: true, shouldHaveHeaders: false }, { model: 'claude-3.5-sonnet-latest', promptCache: true, shouldHaveHeaders: false }, @@ -1193,9 +1183,7 @@ describe('getLLMConfig', () => { if (shouldHaveHeaders) { expect(headers).toBeDefined(); - expect((headers as Record)['anthropic-beta']).toContain( - 'prompt-caching', - ); + expect((headers as Record)['anthropic-beta']).toBeDefined(); } else { expect(headers).toBeUndefined(); } diff --git a/packages/api/src/endpoints/anthropic/vertex.ts b/packages/api/src/endpoints/anthropic/vertex.ts index 116a00875f..12967f1a58 100644 --- a/packages/api/src/endpoints/anthropic/vertex.ts +++ b/packages/api/src/endpoints/anthropic/vertex.ts @@ -79,7 +79,7 @@ export function isAnthropicVertexCredentials(credentials: AnthropicCredentials): /** * Filters anthropic-beta header values to only include those supported by Vertex AI. - * Vertex AI rejects prompt-caching-2024-07-31 but we use 'prompt-caching-vertex' as a + * Vertex AI handles caching differently and we use 'prompt-caching-vertex' as a * marker to trigger cache_control application in the agents package. */ function filterVertexHeaders(headers?: Record): Record | undefined { diff --git a/packages/api/src/endpoints/openai/config.anthropic.spec.ts b/packages/api/src/endpoints/openai/config.anthropic.spec.ts index 7cc8240031..eeb17a311d 100644 --- a/packages/api/src/endpoints/openai/config.anthropic.spec.ts +++ b/packages/api/src/endpoints/openai/config.anthropic.spec.ts @@ -44,7 +44,7 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { configOptions: { baseURL: 'http://host.docker.internal:4000/v1', defaultHeaders: { - 'anthropic-beta': 'prompt-caching-2024-07-31,context-1m-2025-08-07', + 'anthropic-beta': 'context-1m-2025-08-07', }, }, tools: [], @@ -92,8 +92,7 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { configOptions: { baseURL: 'http://localhost:4000/v1', defaultHeaders: { - 'anthropic-beta': - 'token-efficient-tools-2025-02-19,output-128k-2025-02-19,prompt-caching-2024-07-31', + 'anthropic-beta': 'token-efficient-tools-2025-02-19,output-128k-2025-02-19', }, }, tools: [], @@ -140,8 +139,7 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { configOptions: { baseURL: 'http://localhost:4000/v1', defaultHeaders: { - 'anthropic-beta': - 'token-efficient-tools-2025-02-19,output-128k-2025-02-19,prompt-caching-2024-07-31', + 'anthropic-beta': 'token-efficient-tools-2025-02-19,output-128k-2025-02-19', }, }, tools: [], @@ -182,14 +180,14 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { configOptions: { baseURL: 'https://api.anthropic.proxy.com/v1', defaultHeaders: { - 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15,prompt-caching-2024-07-31', + 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15', }, }, tools: [], }); }); - it('should apply anthropic-beta headers based on model pattern', () => { + it('should apply custom headers without anthropic-beta for models that dont need it', () => { const apiKey = 'sk-custom'; const endpoint = 'Anthropic (via LiteLLM)'; const options = { @@ -227,7 +225,6 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { defaultHeaders: { 'Custom-Header': 'custom-value', Authorization: 'Bearer custom-token', - 'anthropic-beta': 'prompt-caching-2024-07-31', }, }, tools: [], @@ -309,9 +306,6 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { }, configOptions: { baseURL: 'http://proxy.litellm/v1', - defaultHeaders: { - 'anthropic-beta': 'prompt-caching-2024-07-31', - }, }, tools: [], }); @@ -389,9 +383,6 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { }, configOptions: { baseURL: 'http://litellm/v1', - defaultHeaders: { - 'anthropic-beta': 'prompt-caching-2024-07-31', - }, }, tools: [ { @@ -438,9 +429,6 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { }, configOptions: { baseURL: 'http://litellm/v1', - defaultHeaders: { - 'anthropic-beta': 'prompt-caching-2024-07-31', - }, }, tools: [], }); @@ -488,9 +476,6 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { }, configOptions: { baseURL: 'http://litellm/v1', - defaultHeaders: { - 'anthropic-beta': 'prompt-caching-2024-07-31', - }, }, tools: [], }); @@ -541,7 +526,7 @@ describe('getOpenAIConfig - Anthropic Compatibility', () => { configOptions: { baseURL: 'http://litellm/v1', defaultHeaders: { - 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15,prompt-caching-2024-07-31', + 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15', }, }, tools: [],