AI-Anthropic
view release on metacpan or search on metacpan
```bash
perl Makefile.PL
make
make test
make install
```
## Features
- **Messages API** - Full support for Claude chat completions
- **Streaming** - Real-time response streaming with callbacks
- **Vision** - Send images (from files, URLs, or base64)
- **Tool Use** - Function calling support
- **All Models** - Claude 4 Opus, Sonnet, Haiku and older models
## Quick Start
```perl
use AI::Anthropic;
my $claude = AI::Anthropic->new(
lib/AI/Anthropic.pm view on Meta::CPAN
=head2 chat
Full chat interface:
my $response = $claude->chat(
messages => \@messages, # required
system => $system_prompt, # optional
model => $model, # optional, overrides default
max_tokens => $max_tokens, # optional
temperature => 0.7, # optional, 0.0-1.0
stream => \&callback, # optional, for streaming
tools => \@tools, # optional, for function calling
);
=cut
sub chat {
my ($self, %args) = @_;
my $messages = $args{messages}
or croak "messages parameter required";
lib/AI/Anthropic.pm view on Meta::CPAN
}
sub _stream_request {
my ($self, $body, $callback) = @_;
$body->{stream} = \1; # JSON true
my $full_text = '';
my $response_data;
# HTTP::Tiny doesn't support streaming well, so we use a data callback
my $response = $self->{_http}->post(
$self->{api_base} . '/v1/messages',
{
headers => $self->_headers,
content => $self->{_json}->encode($body),
data_callback => sub {
my ($chunk, $res) = @_;
# Parse SSE events
for my $line (split /\n/, $chunk) {
( run in 0.486 second using v1.01-cache-2.11-cpan-140bd7fdf52 )