AI-Anthropic
view release on metacpan or search on metacpan
Changes
examples/basic.pl
lib/AI/Anthropic.pm
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
README.md
t/01-basic.t
tree_structure.txt
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Carp" : "0",
"HTTP::Tiny" : "0.070",
"JSON::PP" : "2.0",
"MIME::Base64" : "0",
"perl" : "5.010"
}
},
"test" : {
"requires" : {
"Test::More" : "0.88"
}
}
},
"bugtracker" : {
"web" : "https://github.com/yourusername/AI-Anthropic/issues"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/yourusername/AI-Anthropic.git",
"web" : "https://github.com/yourusername/AI-Anthropic"
}
},
"version" : "0.01",
"x_serialization_backend" : "JSON::PP version 4.16"
}
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: AI-Anthropic
no_index:
directory:
- t
- inc
requires:
Carp: '0'
HTTP::Tiny: '0.070'
JSON::PP: '2.0'
MIME::Base64: '0'
perl: '5.010'
resources:
bugtracker: https://github.com/yourusername/AI-Anthropic/issues
repository: https://github.com/yourusername/AI-Anthropic.git
version: '0.01'
x_serialization_backend: 'CPAN::Meta::YAML version 0.020'
Makefile.PL view on Meta::CPAN
WriteMakefile(
NAME => 'AI::Anthropic',
VERSION_FROM => 'lib/AI/Anthropic.pm',
ABSTRACT => 'Perl interface to Anthropic Claude API',
AUTHOR => 'Your Name <your@email.com>',
LICENSE => 'perl_5',
MIN_PERL_VERSION => '5.010',
PREREQ_PM => {
'HTTP::Tiny' => '0.070',
'JSON::PP' => '2.0',
'MIME::Base64' => '0',
'Carp' => '0',
},
TEST_REQUIRES => {
'Test::More' => '0.88',
},
META_MERGE => {
'meta-spec' => { version => 2 },
```
## Environment Variables
- `ANTHROPIC_API_KEY` - Your Anthropic API key
## Dependencies
- Perl 5.10+
- HTTP::Tiny
- JSON::PP
- MIME::Base64
All dependencies are core modules or widely available on CPAN.
## Why This Module?
- **Pure Perl** - No XS, works everywhere
- **Minimal dependencies** - Uses core modules where possible
- **Perlish API** - Feels natural to Perl programmers
- **Full featured** - Streaming, vision, tools - all supported
lib/AI/Anthropic.pm view on Meta::CPAN
package AI::Anthropic;
use strict;
use warnings;
use 5.010;
our $VERSION = '0.01';
use Carp qw(croak);
use JSON::PP;
use HTTP::Tiny;
use MIME::Base64 qw(encode_base64);
# Constants
use constant {
API_BASE => 'https://api.anthropic.com',
API_VERSION => '2023-06-01',
DEFAULT_MODEL => 'claude-sonnet-4-20250514',
};
lib/AI/Anthropic.pm view on Meta::CPAN
my $self = {
api_key => $api_key,
model => $args{model} // DEFAULT_MODEL,
max_tokens => $args{max_tokens} // 4096,
timeout => $args{timeout} // 120,
api_base => $args{api_base} // API_BASE,
_http => HTTP::Tiny->new(
timeout => $args{timeout} // 120,
),
_json => JSON::PP->new->utf8->allow_nonref,
};
return bless $self, $class;
}
=head2 message
Simple interface for single message:
my $response = $claude->message("Your question here");
lib/AI/Anthropic.pm view on Meta::CPAN
content => $self->{_json}->encode($body),
}
);
return $self->_handle_response($response);
}
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),
( run in 0.929 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )