Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

533 B
Raw Blame
import type { ModelUsage } from '@lobechat/types';
import type { Pricing } from 'model-bank';

import type { ComputeChatCostOptions } from './computeChatCost';
import { computeChatCost } from './computeChatCost';

export const withUsageCost = (
  usage: ModelUsage,
  pricing?: Pricing,
  options?: ComputeChatCostOptions,
): ModelUsage => {
  if (!pricing) return usage;

  const pricingResult = computeChatCost(pricing, usage, options);
  if (!pricingResult) return usage;

  return { ...usage, cost: pricingResult.totalCost };
};