LLM-API

 view release on metacpan or  search on metacpan

lib/LLM/API.pm  view on Meta::CPAN

reports is '1d' rather than '1h'.

Returns the decoded JSON response as a Perl data structure on success,
or throws an exception containing the HTTP response code and HTTP body.

See L<https://platform.claude.com/docs/en/api/admin/cost_report/retrieve> for more detail.

=head2 headers

    my $headers = $llm->headers;
    my $headers = $llm->headers( 'content-type' => 'application/json' );

Delegates HTTP header construction to the selected provider. For Anthropic,
the returned hash reference includes C<x-api-key> and C<anthropic-version>;
additional header key-value pairs may be supplied as a flat list. Bedrock
uses AWS authentication rather than Anthropic API-key headers.

=head2 pricing

    my ( $input_cost, $output_cost ) = $llm->pricing;
    my ( $input_cost, $output_cost ) = $llm->pricing( $model_name );

lib/LLM/API/Anthropic.pm  view on Meta::CPAN


########################################################################
sub count_input_tokens {
########################################################################
  my ( $class, $self, $content ) = @_;

  die "ERROR: usage: send_prompt(array-ref)\n"
    if !ref $content || reftype($content) ne 'ARRAY';

  my $req = {
    headers => $self->headers( 'content-type' => 'application/json' ),
    content => encode_json(
      { model    => $self->get_model,
        messages => [
          { role    => $self->get_role,
            content => $content,
          }
        ]
      }
    )
  };

lib/LLM/API/Anthropic.pm  view on Meta::CPAN


  return $class->send_messages( $self, [ { role => $self->get_role, content => $content } ] );
}

########################################################################
sub send_messages {
########################################################################
  my ( $class, $self, $messages ) = @_;

  my $req = {
    headers => $self->headers( 'content-type' => 'application/json' ),
    content => encode_json(
      { model      => $self->get_model,
        max_tokens => $self->get_max_tokens,
        messages   => $messages,
      }
    )
  };

  my $rsp
    = HTTP::Tiny->new( timeout => $self->get_timeout )->post( $LLM::API::LLM_URL_BASE . $LLM::API::LLM_MESSAGES_EP, $req );

share/README.md  view on Meta::CPAN

reports is '1d' rather than '1h'.

Returns the decoded JSON response as a Perl data structure on success,
or throws an exception containing the HTTP response code and HTTP body.

See [https://platform.claude.com/docs/en/api/admin/cost\_report/retrieve](https://platform.claude.com/docs/en/api/admin/cost_report/retrieve) for more detail.

## headers

    my $headers = $llm->headers;
    my $headers = $llm->headers( 'content-type' => 'application/json' );

Delegates HTTP header construction to the selected provider. For Anthropic,
the returned hash reference includes `x-api-key` and `anthropic-version`;
additional header key-value pairs may be supplied as a flat list. Bedrock
uses AWS authentication rather than Anthropic API-key headers.

## pricing

    my ( $input_cost, $output_cost ) = $llm->pricing;
    my ( $input_cost, $output_cost ) = $llm->pricing( $model_name );



( run in 1.287 second using v1.01-cache-2.11-cpan-99fa8243a42 )