File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,15 @@ export function fromAnthropicResponse(
309
309
role : 'model' ,
310
310
content : parts . map ( fromAnthropicPart ) ,
311
311
} ;
312
+ let usageCustom : Record < string , number > | undefined = undefined ;
313
+ if ( response . usage . cache_creation_input_tokens ) {
314
+ usageCustom = { } ;
315
+ usageCustom [ 'cacheCreationInputTokens' ] = response . usage . cache_creation_input_tokens ;
316
+ }
317
+ if ( response . usage . cache_read_input_tokens ) {
318
+ usageCustom = usageCustom || { } ;
319
+ usageCustom [ 'cacheReadInputTokens' ] = response . usage . cache_read_input_tokens ;
320
+ }
312
321
return {
313
322
message,
314
323
finishReason : toGenkitFinishReason (
@@ -328,6 +337,7 @@ export function fromAnthropicResponse(
328
337
...getBasicUsageStats ( input . messages , message ) ,
329
338
inputTokens : response . usage . input_tokens ,
330
339
outputTokens : response . usage . output_tokens ,
340
+ custom : usageCustom
331
341
} ,
332
342
} ;
333
343
}
Original file line number Diff line number Diff line change @@ -134,10 +134,12 @@ describe('toAnthropicRequest', () => {
134
134
messages : [
135
135
{
136
136
role : 'user' ,
137
- content : {
138
- type : 'text' ,
139
- text : 'What are the key terms and conditions in this agreement?' ,
140
- } ,
137
+ content : [
138
+ {
139
+ type : 'text' ,
140
+ text : 'What are the key terms and conditions in this agreement?' ,
141
+ } ,
142
+ ] ,
141
143
} ,
142
144
] ,
143
145
} ,
@@ -218,6 +220,8 @@ describe('fromAnthropicResponse', () => {
218
220
usage : {
219
221
input_tokens : 123 ,
220
222
output_tokens : 234 ,
223
+ cache_creation_input_tokens : 0 ,
224
+ cache_read_input_tokens : 0 ,
221
225
} ,
222
226
stop_sequence : null ,
223
227
type : 'message' ,
@@ -300,6 +304,8 @@ describe('fromAnthropicResponse', () => {
300
304
usage : {
301
305
input_tokens : 123 ,
302
306
output_tokens : 234 ,
307
+ cache_creation_input_tokens : 0 ,
308
+ cache_read_input_tokens : 0 ,
303
309
} ,
304
310
content : [
305
311
{
You can’t perform that action at this time.
0 commit comments