🌵 chore: Remove deprecated 'prompt-caching' Anthropic header (#11313)

This commit is contained in:
Danny Avila 2026-01-12 19:12:36 -05:00 committed by GitHub
parent 90521bfb4e
commit 28270bec58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 68 deletions

View file

@ -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);

View file

@ -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;
}
/**

View file

@ -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<string, string>;
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<string, string>;
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<string, string>;
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<string, string>;
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<string, string>)['anthropic-beta']).toContain(
'prompt-caching',
);
expect((headers as Record<string, string>)['anthropic-beta']).toBeDefined();
} else {
expect(headers).toBeUndefined();
}

View file

@ -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<string, string>): Record<string, string> | undefined {

View file

@ -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: [],