SkillKit.Eval.Cost (SkillKit v0.5.0)

Copy Markdown View Source

Derives the USD cost of an eval run from its token usage.

An eval run has two priced components — the agent under test and the LLM judge — each with its own token usage and (possibly different) model. This module resolves each model URI to the id SkillKit.LLM.Pricing keys on, prices each component, and combines them.

A component with no tokens is free regardless of its model, so a skipped judge never makes a run unpriceable. A component with real usage on a model with no known rate is genuinely unknown, so total/1 reports nil rather than an understated figure.

Summary

Functions

Renders a cost as a dollar amount, or "cost unknown" for nil.

Prices usage at model's rate. Returns 0.0 for zero usage, the USD cost for a model with a known rate, or nil when a non-empty usage has no rate.

Sums the cost of each {usage, model} component. Returns nil when any component with real usage can't be priced.

Types

component()

@type component() :: {SkillKit.Eval.Transcript.usage(), String.t() | nil}

Functions

format(cost)

@spec format(float() | nil) :: String.t()

Renders a cost as a dollar amount, or "cost unknown" for nil.

price(usage, model)

@spec price(SkillKit.Eval.Transcript.usage(), String.t() | nil) :: float() | nil

Prices usage at model's rate. Returns 0.0 for zero usage, the USD cost for a model with a known rate, or nil when a non-empty usage has no rate.

total(components)

@spec total([component()]) :: float() | nil

Sums the cost of each {usage, model} component. Returns nil when any component with real usage can't be priced.