| 1 | package Langertha::UsageRecord; | ||
| 2 | # ABSTRACT: Tagged ledger entry combining Usage, Cost, and request metadata | ||
| 3 | 4 | our $VERSION = '0.505'; | |
| 4 | 4 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 4 | ▶ | use Langertha::Usage; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 4 | ▶ | use Langertha::Cost; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 4 | has usage => ( is => 'ro', isa => 'Langertha::Usage', required => 1 ); | |
| 9 | 4 | has cost => ( is => 'ro', isa => 'Langertha::Cost', required => 1 ); | |
| 10 | |||
| 11 | 4 | has model => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 12 | 4 | has provider => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 13 | 4 | has engine => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 14 | 4 | has route => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 15 | 4 | has endpoint => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 16 | |||
| 17 | 4 | has api_key_id => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 18 | |||
| 19 | 4 | has tool_calls => ( is => 'ro', isa => 'Int', default => 0 ); | |
| 20 | 0 | ▶ | has tool_names => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] } ); |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 21 | |||
| 22 | 4 | has duration_ms => ( is => 'ro', isa => 'Maybe[Num]' ); | |
| 23 | 4 | has started_at => ( is => 'ro', isa => 'Maybe[Num]' ); | |
| 24 | 4 | has finished_at => ( is => 'ro', isa => 'Maybe[Num]' ); | |
| 25 | |||
| 26 | 4 | has pricing_version => ( is => 'ro', isa => 'Maybe[Str]' ); | |
| 27 | |||
| 28 | 4 | ▶ | sub to_hash { |
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 29 | 4 | my ($self) = @_; | |
| 30 | return { | ||
| 31 | 4 | provider => $self->provider, | |
| 32 | engine => $self->engine, | ||
| 33 | model => $self->model, | ||
| 34 | route => $self->route, | ||
| 35 | endpoint => $self->endpoint, | ||
| 36 | api_key_id => $self->api_key_id, | ||
| 37 | duration_ms => $self->duration_ms, | ||
| 38 | started_at => $self->started_at, | ||
| 39 | finished_at => $self->finished_at, | ||
| 40 | input_tokens => $self->usage->input_tokens, | ||
| 41 | output_tokens => $self->usage->output_tokens, | ||
| 42 | total_tokens => $self->usage->total_tokens, | ||
| 43 | tool_calls => $self->tool_calls, | ||
| 44 | tool_names => $self->tool_names, | ||
| 45 | input_cost_usd => $self->cost->input_usd + 0, | ||
| 46 | output_cost_usd => $self->cost->output_usd + 0, | ||
| 47 | cache_read_cost_usd => $self->cost->cache_read_usd + 0, | ||
| 48 | cache_write_cost_usd => $self->cost->cache_write_usd + 0, | ||
| 49 | total_cost_usd => $self->cost->total_usd + 0, | ||
| 50 | currency => $self->cost->currency, | ||
| 51 | pricing_version => $self->pricing_version, | ||
| 52 | }; | ||
| 53 | } | ||
| 54 | |||
| 55 | # Make the object transparent to any JSON encoder configured with | ||
| 56 | # convert_blessed => 1 (the house default, see Langertha::Plugin::Langfuse). | ||
| 57 | # to_hash is the complete canonical representation — every attribute is | ||
| 58 | # flattened into the ledger hash, and api_key_id is a normalized identifier | ||
| 59 | # (which key was used), not the credential itself — so this is a plain | ||
| 60 | # delegator, nothing is dropped. | ||
| 61 | 1 | ▶ | sub TO_JSON { shift->to_hash } |
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 62 | |||
| 63 | 4 | __PACKAGE__->meta->make_immutable; | |
| 64 | 4 | 1; | |
| 65 | |||
| 66 | __END__ | ||