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