Skip to content

RunCost

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

Cost of a run. It is computed and written once when the run ends (a price snapshot) — a later change to the price list does not change past values.

public sealed record RunCost : IEquatable<RunCost>

objectRunCost

IEquatable<RunCost>

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

public RunCost()

Gets the cost of the input tokens that were served from the prompt cache, or null when no cache read was priced.

public decimal? CachedInputCost { get; init; }

decimal?

The cached tokens are subtracted from RunCost.InputCost and charged here instead, so the two fields still add up to the run’s input spend and must not be double counted.

An undefined cache rate does not push the run to PricingSource.Unknown: the cached tokens are then priced at the normal input rate and the total stays exactly what it was before this field existed. PricingSource.Unknown means the MODEL price is missing, which is a different fault.

Gets the currency, taken from AgentPrism:Pricing:Currency.

public string? Currency { get; init; }

string?

Gets the input token cost, or null when the price is unknown.

public decimal? InputCost { get; init; }

decimal?

Gets the output token cost, or null when the price is unknown.

public decimal? OutputCost { get; init; }

decimal?

Gets where the price came from.

public required PricingSource Source { get; init; }

PricingSource

public override bool Equals(object? obj)

obj object?

bool

public bool Equals(RunCost? other)

other RunCost?

bool

public override int GetHashCode()

int

public override string ToString()

string

Gets the run’s total cost — input, output and cache read together.

public decimal? Total()

decimal?

null when the run was never priced at all. Zero would say “it cost nothing”, which is a different claim.

Every caller that needs “what did this run cost” must use THIS, never InputCost + OutputCost. RunCost.CachedInputCost is a third addend, not a subset of RunCost.InputCost: the resolver subtracts the cached tokens out of the input charge and bills them here. A hand written two-term sum under-reports every run that hit the prompt cache — and a quota ceiling computed that way can be exceeded.

public static bool operator ==(RunCost? left, RunCost? right)

left RunCost?

right RunCost?

bool

public static bool operator !=(RunCost? left, RunCost? right)

left RunCost?

right RunCost?

bool