What a call cost, in US dollars (Request.cost, a Decimal), and where the
figure came from. The first source that has a price wins:
"provider"— the cost the provider reports inusage.cost(OpenRouter);"catalogue"— the price the operator's catalogue lists for the model (OpenRouter'spricing, throughPhoenixKitAI.Capabilities);"manual"— the price entered on the endpoint (PhoenixKitAI.ManualPrice);"table"— Anthropic's built-in rates (PhoenixKitAI.AnthropicPricing, for an Anthropic endpoint), last, so a manual price corrects them.
The model priced is the one the answer names; when no source prices it,
the endpoint's model is tried — so an answer naming an unknown model is
still counted when the endpoint's model has a price, and a money limit is
not bypassed by it. A catalogue price is per TOKEN (OpenRouter's pricing),
a manual price and Anthropic's rates per 1M tokens: each base has its own
path (ManualPrice.cost/3 for the second), and the total is rounded once, to
the column's 18 places (Money.round_cost/1). A call without tokens (an answer with no usage, or
an empty one) says nothing about its size and gets no cost, not a priced $0.
Chat, embeddings and the vision verbs (describe_image/3, extract_text/3,
compare_images/4 — chat calls with images; the model sent is the call's
model:, else the endpoint's) are priced here. Making or editing images
(generate_image/3, edit_image/4, process_image/4) is priced per image
or per call, which a price per token does not fit: those rows keep only the
provider's own cost.
Summary
Functions
A call's cost and what its usage row's metadata gets: reported (the
provider's cost, dollars) with cost_source: "provider", else the first
priced source for model then for the endpoint's model, else {nil, %{}} —
and {nil, %{}} for a call without tokens. The cost is rounded to the
column's 18 places.
Whether some source prices calls on the endpoint's model: its provider reports what a call cost (OpenRouter), or a catalogue, a manual or the built-in price is there for it.
Where a usage row's cost came from (cost_source), or nil.
Types
@type source() :: String.t()
Functions
@spec for_call( PhoenixKitAI.Endpoint.t() | map(), String.t() | nil, Decimal.t() | nil, integer() | nil, integer() | nil ) :: {Decimal.t() | nil, map()}
A call's cost and what its usage row's metadata gets: reported (the
provider's cost, dollars) with cost_source: "provider", else the first
priced source for model then for the endpoint's model, else {nil, %{}} —
and {nil, %{}} for a call without tokens. The cost is rounded to the
column's 18 places.
@spec reports_cost?(PhoenixKitAI.Endpoint.t() | map()) :: boolean()
Whether some source prices calls on the endpoint's model: its provider reports what a call cost (OpenRouter), or a catalogue, a manual or the built-in price is there for it.
Where a usage row's cost came from (cost_source), or nil.