227
*/
228
export function createPricingMetaFromBilling(billing: ICAPIModelBilling | undefined, priceCategory?: string, category?: string): Record<string, unknown> | undefined {
230
>
const longContext = tokenPrices?.longContext;
231
>
232
>
// Only emit long-context costs when there is an actual surcharge (at least
233
>
// one price differs from default). When emitting, fall back to the default-
234
>
// tier value for any field the long-context tier does not specify so the
235
>
// hover table renders complete rows without gaps.
236
>
const showLongContext = longContext !== undefined && (
237
(longContext.inputPrice !== undefined && longContext.inputPrice !== tokenPrices?.inputPrice) ||
238
(longContext.outputPrice !== undefined && longContext.outputPrice !== tokenPrices?.outputPrice) ||
239
(longContext.cachePrice !== undefined && longContext.cachePrice !== tokenPrices?.cachePrice) ||
240
(longContext.cacheWritePrice !== undefined && longContext.cacheWritePrice !== tokenPrices?.cacheWritePrice)
242
>
243
>
return createAgentModelPricingMeta({
244
>
multiplierNumeric: typeof billing?.multiplier === 'number' ? billing.multiplier : undefined,
245
>
inputCost: tokenPrices?.inputPrice,
246
>
cacheCost: tokenPrices?.cachePrice,
247
>
cacheWriteCost: tokenPrices?.cacheWritePrice,
248
>
outputCost: tokenPrices?.outputPrice,
249
>
longContextInputCost: showLongContext ? (longContext.inputPrice ?? tokenPrices?.inputPrice) : undefined,
250
>
longContextCacheCost: showLongContext ? (longContext.cachePrice ?? tokenPrices?.cachePrice) : undefined,
251
>
longContextCacheWriteCost: showLongContext ? (longContext.cacheWritePrice ?? tokenPrices?.cacheWritePrice) : undefined,
252
>
longContextOutputCost: showLongContext ? (longContext.outputPrice ?? tokenPrices?.outputPrice) : undefined,
253
>
priceCategory: priceCategory ?? (typeof billing?.priceCategory === 'string' ? billing.priceCategory : undefined),
254
>
category,
255
>
discountPercent: typeof billing?.discountPercent === 'number' ? billing.discountPercent : undefined,
256
>
promo: billing?.promo,
257
>
});
258
>
}
259
260
/**