AI-Anthropic
view release on metacpan or search on metacpan
# AI::Anthropic
Perl interface to Anthropic's Claude API.
## Synopsis
```perl
use AI::Anthropic;
my $claude = AI::Anthropic->new(
api_key => 'sk-ant-api03-your-key-here',
);
# Simple message
print $claude->message("What is the meaning of life?");
# With system prompt
my $response = $claude->chat(
system => 'You are a helpful Perl programmer.',
messages => [
{ role => 'user', content => 'How do I read a file?' },
],
);
print "Response: ", $response->text, "\n";
print "Tokens: ", $response->total_tokens, "\n";
```
## Installation
From CPAN:
```bash
cpanm AI::Anthropic
```
Or manually:
```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(
api_key => 'sk-ant-api03-your-key-here',
);
print $claude->message("Hello!");
```
## Streaming
```perl
$claude->chat(
messages => [ { role => 'user', content => 'Tell me a story' } ],
stream => sub {
my ($chunk) = @_;
print $chunk;
STDOUT->flush;
},
);
```
## Vision (Images)
```perl
# From file
my $response = $claude->chat(
messages => [
{
role => 'user',
content => [
{ type => 'text', text => 'What is in this image?' },
{ type => 'image', path => '/path/to/image.jpg' },
],
},
],
);
# From URL
my $response = $claude->chat(
messages => [
{
role => 'user',
content => [
{ type => 'text', text => 'Describe this image' },
{ type => 'image', url => 'https://example.com/image.png' },
],
},
],
);
```
## Tool Use (Function Calling)
( run in 0.702 second using v1.01-cache-2.11-cpan-140bd7fdf52 )