NAME

Langertha::Engine::Anthropic - Anthropic API

VERSION

version 0.100

SYNOPSIS

use Langertha::Engine::Anthropic;

# Basic usage
my $claude = Langertha::Engine::Anthropic->new(
  api_key => $ENV{ANTHROPIC_API_KEY},
  model => 'claude-sonnet-4-5-20250929',
  response_size => 4096,
  temperature => 0.7,
);

# Simple chat
my $response = $claude->simple_chat('Generate Perl Moose classes to represent GeoJSON data types');
print $response;

# Streaming
$claude->simple_chat_stream(sub {
  my ($chunk) = @_;
  print $chunk->content;
}, 'Tell me about Perl');

# Async with Future::AsyncAwait
use Future::AsyncAwait;

async sub ask_claude {
  my $response = await $claude->simple_chat_f('What is the meaning of life?');
  say $response;
}

DESCRIPTION

This module provides access to Anthropic's Claude models via their API. Claude is a family of large language models known for their helpfulness, harmlessness, and honesty.

Available Models (February 2026):

  • claude-opus-4-6-20250514 - Most capable model with 1M token context, strongest coding, planning, and debugging capabilities. Released February 5, 2026. Best for complex tasks, code review, and agentic workflows.

  • claude-sonnet-4-5-20250929 - Balanced performance and speed (default). Released November 24, 2025. Excellent for most general-purpose tasks.

  • claude-haiku-4-5-20251001 - Fastest and most cost-efficient model. Matches Sonnet 4's performance on coding, computer use, and agent tasks while being significantly cheaper.

The Claude model family is organized by capability: Haiku (fastest/cheapest), Sonnet (balanced), and Opus (most capable/expensive).

Features:

  • Streaming support (SSE-based)

  • System prompts

  • Temperature control

  • Response size limits (max_tokens)

  • Async/await support via Future::AsyncAwait

  • Dynamic model discovery via API

  • Advanced parameters: effort (thinking depth), inference_geo (data residency)

THIS API IS WORK IN PROGRESS

NEW PARAMETERS (FEBRUARY 2026)

Anthropic has introduced new parameters for enhanced control:

effort

Controls the depth of thinking for reasoning models. Values: low, medium, high.

my $claude = Langertha::Engine::Anthropic->new(
  api_key => $ENV{ANTHROPIC_API_KEY},
  model => 'claude-opus-4-6-20250514',
  effort => 'high',  # More thorough reasoning
);

inference_geo

Controls data residency for inference. Values: us, eu.

my $claude = Langertha::Engine::Anthropic->new(
  api_key => $ENV{ANTHROPIC_API_KEY},
  model => 'claude-sonnet-4-5-20250929',
  inference_geo => 'eu',  # Process in EU region
);

LISTING AVAILABLE MODELS

Dynamically fetch available models from the Anthropic API (with cursor pagination):

# Get simple list of model IDs
my $model_ids = $engine->list_models;
# Returns: ['claude-opus-4-6-20250514', 'claude-sonnet-4-5-20250929', ...]

# Get full model objects with metadata
my $models = $engine->list_models(full => 1);
# Returns: [{id => '...', display_name => '...', created_at => '...'}, ...]

# Force refresh (bypass cache)
my $models = $engine->list_models(force_refresh => 1);

Caching: Results are cached for 1 hour by default. Configure the TTL:

my $engine = Langertha::Engine::Anthropic->new(
  api_key => $ENV{ANTHROPIC_API_KEY},
  models_cache_ttl => 1800, # 30 minutes
);

# Clear the cache manually
$engine->clear_models_cache;

Deprecation Notice: The all_models() method returns a hardcoded list and is deprecated. Use list_models() for up-to-date model availability.

GETTING AN API KEY

Sign up at https://console.anthropic.com/ and generate an API key.

Set the environment variable:

export ANTHROPIC_API_KEY=your-key-here
# Or use LANGERTHA_ANTHROPIC_API_KEY

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudss.us/

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

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