MCPcopy Create free account
hub / github.com/code-with-antonio/nightcode / calculateCreditsForUsage

Function calculateCreditsForUsage

packages/server/src/lib/credits.ts:86–99  ·  view source on GitHub ↗
({
  provider,
  model,
  usage,
}: CalculateCreditsForUsageParams)

Source from the content-addressed store, hash-verified

84
85
86export function calculateCreditsForUsage({
87 provider,
88 model,
89 usage,
90}: CalculateCreditsForUsageParams): BillableUsage {
91 const tokenCounts = getTokenCounts(usage);
92 const pricing = getModelPricing(provider, model);
93 const estimatedCostUsd = estimateCostUsd(tokenCounts, pricing);
94 const credits = convertUsdToCredits(estimatedCostUsd);
95
96 return {
97 credits,
98 };
99};

Callers 1

onFinishFunction · 0.90

Calls 4

getTokenCountsFunction · 0.85
getModelPricingFunction · 0.85
estimateCostUsdFunction · 0.85
convertUsdToCreditsFunction · 0.85

Tested by

no test coverage detected