Langertha
view release on metacpan or search on metacpan
lib/Langertha/Engine/AnthropicBase.pm view on Meta::CPAN
anthropic-ratelimit-input-tokens-remaining
anthropic-ratelimit-input-tokens-reset
anthropic-ratelimit-output-tokens-limit
anthropic-ratelimit-output-tokens-remaining
anthropic-ratelimit-output-tokens-reset
)) {
my $val = $http_response->header($name);
$raw{$name} = $val if defined $val;
}
return undef unless %raw;
require Langertha::RateLimit;
return Langertha::RateLimit->new(
( defined $raw{'anthropic-ratelimit-requests-limit'} ? ( requests_limit => $raw{'anthropic-ratelimit-requests-limit'} + 0 ) : () ),
( defined $raw{'anthropic-ratelimit-requests-remaining'} ? ( requests_remaining => $raw{'anthropic-ratelimit-requests-remaining'} + 0 ) : () ),
( defined $raw{'anthropic-ratelimit-requests-reset'} ? ( requests_reset => $raw{'anthropic-ratelimit-requests-reset'} ) : () ),
( defined $raw{'anthropic-ratelimit-tokens-limit'} ? ( tokens_limit => $raw{'anthropic-ratelimit-tokens-limit'} + 0 ) : () ),
( defined $raw{'anthropic-ratelimit-tokens-remaining'} ? ( tokens_remaining => $raw{'anthropic-ratelimit-tokens-remaining'} + 0 ) : () ),
( defined $raw{'anthropic-ratelimit-tokens-reset'} ? ( tokens_reset => $raw{'anthropic-ratelimit-tokens-reset'} ) : () ),
raw => \%raw,
);
}
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Langertha::Engine::AnthropicBase - Base class for Anthropic-compatible engines
=head1 VERSION
version 0.502
=head1 SYNOPSIS
package My::AnthropicCompatible;
use Moose;
extends 'Langertha::Engine::AnthropicBase';
has '+url' => ( default => sub { 'https://api.example.com' } );
sub _build_api_key { $ENV{MY_API_KEY} || die "MY_API_KEY required" }
sub default_model { 'my-model-v1' }
__PACKAGE__->meta->make_immutable;
=head1 DESCRIPTION
Intermediate base class for engines speaking the Anthropic-compatible
C</v1/messages> format. Extends L<Langertha::Engine::Remote> and composes
models/chat/streaming plus Anthropic-style tool calling and response parsing.
Concrete engines extending this class include
L<Langertha::Engine::Anthropic>, L<Langertha::Engine::MiniMax>, and
L<Langertha::Engine::LMStudioAnthropic>.
B<THIS API IS WORK IN PROGRESS>
=head2 api_key
Anthropic-compatible API key sent as C<x-api-key>. Subclasses typically
override C<_build_api_key> to read a provider-specific environment variable.
=head2 api_version
The Anthropic API version header sent with every request. Defaults to
C<2023-06-01>.
=head2 effort
Controls the depth of thinking for reasoning models. Values: C<low>, C<medium>,
C<high>. When set, passed as the C<effort> parameter in the API request.
my $claude = Langertha::Engine::Anthropic->new(
api_key => $ENV{ANTHROPIC_API_KEY},
model => 'claude-opus-4-6',
effort => 'high',
);
=head2 inference_geo
Controls data residency for inference. Values: C<us>, C<eu>. When set, passed
as the C<inference_geo> parameter to keep processing in the specified region.
my $claude = Langertha::Engine::Anthropic->new(
api_key => $ENV{ANTHROPIC_API_KEY},
inference_geo => 'eu',
);
=head2 list_models
my $model_ids = $engine->list_models;
my $models = $engine->list_models(full => 1);
my $models = $engine->list_models(force_refresh => 1);
Fetches available models from the Anthropic API using cursor pagination.
Returns an ArrayRef of model ID strings by default, or full model objects
when C<full => 1> is passed. Results are cached for C<models_cache_ttl>
seconds (default: 3600). Pass C<force_refresh => 1> to bypass the cache.
=head2 _parse_rate_limit_headers
Parses C<anthropic-ratelimit-*> headers from the HTTP response into a
L<Langertha::RateLimit> object. The C<raw> hash captures extras like
C<input-tokens-limit> and C<output-tokens-limit>.
=head1 SEE ALSO
=over
=item * L<https://status.anthropic.com/> - Anthropic service status
( run in 0.647 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )