@@ -179,43 +179,46 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
179179 stream : true ,
180180 ...nativeToolParams ,
181181 }
182+ const requestOptions = ( ( ) => {
183+ // prompt caching: https://x.com/alexalbert__/status/1823751995901272068
184+ // https://github.com/anthropics/anthropic-sdk-typescript?tab=readme-ov-file#default-headers
185+ // https://github.com/anthropics/anthropic-sdk-typescript/commit/c920b77fc67bd839bfeb6716ceab9d7c9bbe7393
186+
187+ // Then check for models that support prompt caching
188+ switch ( modelId ) {
189+ case "claude-sonnet-5" :
190+ case "claude-sonnet-4-6" :
191+ case "claude-sonnet-4-5" :
192+ case "claude-sonnet-4-20250514" :
193+ case "claude-opus-4-6" :
194+ case "claude-opus-4-7" :
195+ case "claude-opus-4-8" :
196+ case "claude-opus-5" :
197+ case "claude-opus-5-5" :
198+ case "claude-fable-5-1" :
199+ case "claude-fable-5" :
200+ case "claude-opus-4-5-20251101" :
201+ case "claude-opus-4-1-20250805" :
202+ case "claude-opus-4-20250514" :
203+ case "claude-3-7-sonnet-20250219" :
204+ case "claude-3-5-sonnet-20241022" :
205+ case "claude-3-5-haiku-20241022" :
206+ case "claude-3-opus-20240229" :
207+ case "claude-haiku-4-5-20251001" :
208+ case "claude-3-haiku-20240307" :
209+ betas . push ( "prompt-caching-2024-07-31" )
210+ return { headers : { "anthropic-beta" : betas . join ( "," ) } }
211+ default :
212+ return undefined
213+ }
214+ } ) ( )
215+ metadata ?. rawApiDump ?. request ( this . providerName , { params : requestParams , requestOptions } )
182216 stream = await this . client . messages . create (
183217 requestParams as Anthropic . Messages . MessageCreateParamsStreaming ,
184- ( ( ) => {
185- // prompt caching: https://x.com/alexalbert__/status/1823751995901272068
186- // https://github.com/anthropics/anthropic-sdk-typescript?tab=readme-ov-file#default-headers
187- // https://github.com/anthropics/anthropic-sdk-typescript/commit/c920b77fc67bd839bfeb6716ceab9d7c9bbe7393
188-
189- // Then check for models that support prompt caching
190- switch ( modelId ) {
191- case "claude-sonnet-5" :
192- case "claude-sonnet-4-6" :
193- case "claude-sonnet-4-5" :
194- case "claude-sonnet-4-20250514" :
195- case "claude-opus-4-6" :
196- case "claude-opus-4-7" :
197- case "claude-opus-4-8" :
198- case "claude-opus-5" :
199- case "claude-opus-5-5" :
200- case "claude-fable-5-1" :
201- case "claude-fable-5" :
202- case "claude-opus-4-5-20251101" :
203- case "claude-opus-4-1-20250805" :
204- case "claude-opus-4-20250514" :
205- case "claude-3-7-sonnet-20250219" :
206- case "claude-3-5-sonnet-20241022" :
207- case "claude-3-5-haiku-20241022" :
208- case "claude-3-opus-20240229" :
209- case "claude-haiku-4-5-20251001" :
210- case "claude-3-haiku-20240307" :
211- betas . push ( "prompt-caching-2024-07-31" )
212- return { headers : { "anthropic-beta" : betas . join ( "," ) } }
213- default :
214- return undefined
215- }
216- } ) ( ) ,
218+ requestOptions ,
217219 )
218220 } catch ( error ) {
221+ metadata ?. rawApiDump ?. error ( this . providerName , error )
219222 TelemetryService . instance . captureException (
220223 new ApiProviderError (
221224 error instanceof Error ? error . message : String ( error ) ,
@@ -240,10 +243,12 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
240243 stream : true ,
241244 ...nativeToolParams ,
242245 }
246+ metadata ?. rawApiDump ?. request ( this . providerName , { params : requestParams } )
243247 stream = ( await this . client . messages . create (
244248 requestParams as Anthropic . Messages . MessageCreateParamsStreaming ,
245249 ) ) as any
246250 } catch ( error ) {
251+ metadata ?. rawApiDump ?. error ( this . providerName , error )
247252 TelemetryService . instance . captureException (
248253 new ApiProviderError (
249254 error instanceof Error ? error . message : String ( error ) ,
@@ -264,6 +269,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
264269 let cacheReadTokens = 0
265270
266271 for await ( const chunk of stream ) {
272+ metadata ?. rawApiDump ?. event ( this . providerName , chunk )
267273 switch ( chunk . type ) {
268274 case "message_start" : {
269275 // Tells us cache reads/writes/input/output.
0 commit comments