AI-Anthropic

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

      },
      "runtime" : {
         "requires" : {
            "Carp" : "0",
            "HTTP::Tiny" : "0.070",
            "JSON::PP" : "2.0",
            "MIME::Base64" : "0",
            "perl" : "5.010"
         }
      },
      "test" : {
         "requires" : {
            "Test::More" : "0.88"
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "web" : "https://github.com/yourusername/AI-Anthropic/issues"
      },

README.md  view on Meta::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

README.md  view on Meta::CPAN

- **Full featured** - Streaming, vision, tools - all supported
- **Well documented** - POD and examples included

## See Also

- [Anthropic API Documentation](https://docs.anthropic.com/)
- [OpenAI::API](https://metacpan.org/pod/OpenAI::API) - Similar module for OpenAI

## Contributing

Pull requests welcome! Please include tests for new features.

## License

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

## Author

Your Name <your@email.com>

t/01-basic.t  view on Meta::CPAN

{
    local $ENV{ANTHROPIC_API_KEY};
    eval {
        my $claude = AI::Anthropic->new();
    };
    like($@, qr/API key required/, 'Dies without API key');
}

# Test object creation with API key
{
    my $claude = AI::Anthropic->new(api_key => 'test-key-123');
    isa_ok($claude, 'AI::Anthropic');
}

# Test models list
{
    my $claude = AI::Anthropic->new(api_key => 'test');
    my @models = $claude->models;
    ok(@models > 0, 'models() returns list');
    ok(grep { /claude/ } @models, 'models contain claude');
}

# Test response object
{
    my $response = AI::Anthropic::Response->new(
        text        => 'Hello!',
        model       => 'claude-sonnet-4-20250514',

t/01-basic.t  view on Meta::CPAN

    is($response->text, 'Hello!', 'Response text');
    is($response->model, 'claude-sonnet-4-20250514', 'Response model');
    is($response->input_tokens, 10, 'Input tokens');
    is($response->output_tokens, 5, 'Output tokens');
    is($response->total_tokens, 15, 'Total tokens');
    
    # Test stringification
    is("$response", 'Hello!', 'Response stringifies to text');
}

done_testing();



( run in 2.045 seconds using v1.01-cache-2.11-cpan-2398b32b56e )