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 -1 variable-pricing sentinel (see is-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.

OpenRouter::API v0.2.1

Raku client for OpenRouter's non-inference REST API

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Cro::HTTP:ver<0.8.11>:auth<zef:cro>JSON::Fast:ver<0.21.0+>:auth<zef:timo>

Test Dependencies

Provides

  • OpenRouter::API
  • OpenRouter::API::Client
  • OpenRouter::API::Filter
  • OpenRouter::API::Pricing
  • OpenRouter::API::Result::ActivityRow
  • OpenRouter::API::Result::Credits
  • OpenRouter::API::Result::Endpoint
  • OpenRouter::API::Result::Generation
  • OpenRouter::API::Result::Model
  • OpenRouter::API::Result::Provider

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.