Claude: set cache TTL to 1h
| @@ -174,7 +174,7 @@ async function sendClaudeRequest(request, response) { | ||
| 174 | 174 | }; |
| 175 | 175 | if (useSystemPrompt) { |
| 176 | 176 | if (enableSystemPromptCache && Array.isArray(convertedPrompt.systemPrompt) && convertedPrompt.systemPrompt.length) { |
| 177 | 177 | convertedPrompt.systemPrompt[convertedPrompt.systemPrompt.length - 1]['cache_control'] = { type: 'ephemeral', ttl: '1h' }; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | requestBody.system = convertedPrompt.systemPrompt; |
| @@ -190,7 +190,7 @@ async function sendClaudeRequest(request, response) { | ||
| 190 | 190 | .map(fn => ({ name: fn.name, description: fn.description, input_schema: fn.parameters })); |
| 191 | 191 | |
| 192 | 192 | if (enableSystemPromptCache && requestBody.tools.length) { |
| 193 | 193 | requestBody.tools[requestBody.tools.length - 1]['cache_control'] = { type: 'ephemeral', ttl: '1h' }; |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
| @@ -199,7 +199,7 @@ async function sendClaudeRequest(request, response) { | ||
| 199 | 199 | 'type': 'web_search_20250305', |
| 200 | 200 | 'name': 'web_search', |
| 201 | 201 | }]; |
| 202 | 202 | requestBody.tools = [...webSearchTool, ...(requestBody.tools || []), ...webSearchTool]; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | if (cachingAtDepth !== -1) { |
| @@ -208,6 +208,7 @@ async function sendClaudeRequest(request, response) { | ||
| 208 | 208 | |
| 209 | 209 | if (enableSystemPromptCache || cachingAtDepth !== -1) { |
| 210 | 210 | betaHeaders.push('prompt-caching-2024-07-31'); |
| 211 | + betaHeaders.push('extended-cache-ttl-2025-04-11'); | |
| 211 | 212 | } |
| 212 | 213 | |
| 213 | 214 | const reasoningEffort = request.body.reasoning_effort; |
| @@ -869,7 +869,7 @@ export function cachingAtDepthForClaude(messages, cachingAtDepth) { | ||
| 869 | 869 | if (messages[i].role !== previousRoleName) { |
| 870 | 870 | if (depth === cachingAtDepth || depth === cachingAtDepth + 2) { |
| 871 | 871 | const content = messages[i].content; |
| 872 | 872 | content[content.length - 1].cache_control = { type: 'ephemeral', ttl: '1h' }; |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | if (depth === cachingAtDepth + 2) { |