LLM-API

 view release on metacpan or  search on metacpan

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


########################################################################
sub count_input_tokens {
########################################################################
  my ( $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.pm  view on Meta::CPAN


########################################################################
sub send_prompt {
########################################################################
  my ( $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,
        max_tokens => $self->get_max_tokens,
        messages   => [
          { role    => $self->get_role,
            content => $content,
          }
        ]
      }
    )

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' );

Builds and returns a hash reference of HTTP request headers. Always includes
the x-api-key and anthropic-version headers. Additional header key-value pairs
may be supplied as a flat list and are merged into the returned hash.

=head2 pricing

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

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' );

Builds and returns a hash reference of HTTP request headers. Always includes
the x-api-key and anthropic-version headers. Additional header key-value pairs
may be supplied as a flat list and are merged into the returned hash.

## pricing

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



( run in 2.225 seconds using v1.01-cache-2.11-cpan-800906f7e73 )