@@ -158,11 +158,13 @@ export async function handler(
158158 Object . entries ( obj ) . flatMap ( ( [ k , v ] ) => {
159159 if ( Array . isArray ( v ) ) return [ [ k , v ] ]
160160 if ( typeof v === "object" ) return [ [ k , replacer ( v ) ] ]
161- if ( v === "$ip" ) return [ [ k , ip ] ]
162- if ( v === "$workspace" ) return authInfo ?. workspaceID ? [ [ k , authInfo ?. workspaceID ] ] : [ ]
163- if ( v . startsWith ( "$header." ) ) {
164- const headerValue = input . request . headers . get ( v . slice ( 8 ) )
165- return headerValue ? [ [ k , headerValue ] ] : [ ]
161+ if ( typeof v === "string" ) {
162+ if ( v === "$ip" ) return [ [ k , ip ] ]
163+ if ( v === "$workspace" ) return authInfo ?. workspaceID ? [ [ k , authInfo ?. workspaceID ] ] : [ ]
164+ if ( v . startsWith ( "$header." ) ) {
165+ const headerValue = input . request . headers . get ( v . slice ( 8 ) )
166+ return headerValue ? [ [ k , headerValue ] ] : [ ]
167+ }
166168 }
167169 return [ [ k , v ] ]
168170 } ) ,
@@ -917,6 +919,13 @@ export async function handler(
917919 "tokens.cache_read" : cacheReadTokens ,
918920 "tokens.cache_write_5m" : cacheWrite5mTokens ,
919921 "tokens.cache_write_1h" : cacheWrite1hTokens ,
922+ "cost.input.microcents" : centsToMicroCents ( inputCost ) ,
923+ "cost.output.microcents" : centsToMicroCents ( outputCost ) ,
924+ "cost.reasoning.microcents" : reasoningCost ? centsToMicroCents ( reasoningCost ) : undefined ,
925+ "cost.cache_read.microcents" : cacheReadCost ? centsToMicroCents ( cacheReadCost ) : undefined ,
926+ "cost.cache_write.microcents" : cacheWrite5mCost ? centsToMicroCents ( cacheWrite5mCost ) : undefined ,
927+ "cost.total.microcents" : centsToMicroCents ( totalCostInCent ) ,
928+ // deprecated - remove after May 20, 2026
920929 "cost.input" : Math . round ( inputCost ) ,
921930 "cost.output" : Math . round ( outputCost ) ,
922931 "cost.reasoning" : reasoningCost ? Math . round ( reasoningCost ) : undefined ,
0 commit comments