Skip to content

estimateCost

estimateCost(inputTokens, outputTokens, rates): number

Defined in: backend/src/shared.ts:212

Estimate request cost based on token counts and provider rates.

number

Estimated input token count

number

Estimated output token count (defaults to maxTokens or 1000)

CostRates

Cost rates per million tokens

number

Estimated cost in USD

const cost = estimateCost(1000, 500, {
inputPer1M: 3.00, // $3 per 1M input tokens
outputPer1M: 15.00, // $15 per 1M output tokens
});
// cost ≈ $0.0105