NAME
Langertha::Pricing - Model→price catalog producing Langertha::Cost from Langertha::Usage
VERSION
version 0.503
SYNOPSIS
my $pricing = Langertha::Pricing->new(
rules => {
'my-model' => {
input_per_million => 3,
output_per_million => 15,
cached_input_per_million => 0.30, # optional
cache_write_per_million => 3.75, # optional
},
},
);
my $cost = $pricing->cost_for( $response->usage, $response->model );
printf "%.6f %s\n", $cost->total_usd, $cost->currency;
DESCRIPTION
Turns a Langertha::Usage into a Langertha::Cost from price rules you supply. Langertha ships no prices: provider prices change too often.
rules
HashRef of model id to rule. A rule is a HashRef of USD per 1,000,000 tokens:
input_per_million- input (prompt) tokensoutput_per_million- output (completion) tokenscached_input_per_million- optional; tokens read from the prompt cache ("cached_tokens" in Langertha::Usage)cache_write_per_million- optional; tokens written to the prompt cache ("cache_write_tokens" in Langertha::Usage)
A missing input_per_million or output_per_million counts as 0.
default_rule
Rule used when the model has no entry in "rules". undef by default, so an unknown model costs nothing.
rule_for
my $rule = $pricing->rule_for($model);
The rule for $model, else "default_rule".
cost_for
my $cost = $pricing->cost_for( $usage, $model );
Prices $usage with the rule for $model and returns a Langertha::Cost.
A rule with neither cache key prices all of input_tokens at input_per_million, whatever part of it was cached, and sets no cache amounts.
A rule with at least one cache key prices each token once, in one of three amounts. input_usd covers "uncached_input_tokens" in Langertha::Usage; cache_read_usd covers the cache reads at cached_input_per_million; cache_write_usd covers the cache writes at cache_write_per_million. A cache key the rule does not have falls back to input_per_million, so no discount is assumed. On wires that count the cache tokens inside the input count (OpenAI, Open-Responses, Gemini, AKI.IO native) they are taken out of it; on Anthropic's wire, which counts them beside it, they are added (see "input_includes_cache" in Langertha::Usage).
SEE ALSO
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.
IRC
Join #langertha on irc.perl.org or message Getty directly.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.