OpenRouter::API::Pricing
NAME
OpenRouter::API::Pricing - Shared wire-price parsing for Result classes
SYNOPSIS
use OpenRouter::API::Pricing;
my $p = parse-price(%data<pricing><prompt>);
my $variable = is-price-sentinel(%data<pricing><prompt>);
DESCRIPTION
Internal helper used by every OpenRouter::API::Result::* class
that exposes a per-token price (Model, Endpoint). It is in
provides only because those classes load it; it is not part of the
public API. It exists so the sentinel rule below lives in exactly one
place instead of being copy-pasted per class.
OpenRouter sends prices as decimal strings (e.g. "0.000005"), but
reserves the literal value -1 as a sentinel meaning "variable /
indeterminate" ā used on router models (e.g. openrouter/auto)
whose real cost depends on which underlying model a request gets
routed to. -1 is never a real price.
the field is absent,
the value doesn't parse as a number (defensive ā a malformed value returns undefined rather than throwing),
the value is the
-1variable-pricing sentinel (seeis-price-sentinel) ā the real price is unknown / model-dependent, not negative one,the value is any OTHER negative number, which is malformed wire data (a price can't be negative) and is reported as undefined rather than propagated.