| 1 | package Langertha::Engine::AKIAnthropic; | ||||||||||||
| 2 | # ABSTRACT: AKI.IO via Anthropic-compatible API | ||||||||||||
| 3 | 16 | our $VERSION = '0.505'; | |||||||||||
| 4 | 16 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 16 | ▶ | use Carp qw( croak ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 16 | extends 'Langertha::Engine::AnthropicBase'; | |||||||||||
| 8 | |||||||||||||
| 9 | 16 | with 'Langertha::Role::StaticModels'; | |||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | # AnthropicBase->chat_request appends '/v1/messages' to url; the default must | ||||||||||||
| 13 | # therefore stop at '/anthropic' so the composed endpoint is a single | ||||||||||||
| 14 | # '/anthropic/v1/messages' (a '/anthropic/v1' default double-stacks to | ||||||||||||
| 15 | # '/anthropic/v1/v1/messages' -> HTTP 404). AKI.IO documents the same rule for | ||||||||||||
| 16 | # the Anthropic Python SDK: "AKI.IO API internally appends /v1/messages, so we | ||||||||||||
| 17 | # recommend using https://aki.io/anthropic for the base_url instead." | ||||||||||||
| 18 | has '+url' => ( | ||||||||||||
| 19 | lazy => 1, | ||||||||||||
| 20 | 5 | ▶ | default => sub { 'https://aki.io/anthropic' }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 16 | ); | |||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | sub _build_api_key { | ||||||||||
|
Subroutine
_build_api_key: called CC=2 SCAR=6.9
| |||||||||||||
| 24 | 2 | my ( $self ) = @_; | |||||||||||
| 25 | return $ENV{LANGERTHA_AKI_API_KEY} | ||||||||||||
| 26 | 2 | ▶ | || croak "".(ref $self)." requires LANGERTHA_AKI_API_KEY or api_key set"; | ||||||||||
|
Condition100%2/2
$ENV{'LANGERTHA_AKI_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_AKI_API_KEY or api_key set')
MC/DC100%1/1
$ENV{'LANGERTHA_AKI_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_AKI_API_KEY or api_key set')
$ENV{'LANGERTHA_AKI_API_KEY'}
Truth table100%2/2
A
A= $ENV{'LANGERTHA_AKI_API_KEY'}
| |||||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | # gpt-oss-120b replaces the EOL llama3-chat-8b (AKI.IO end-of-life 2026-09-30) | ||||||||||||
| 31 | # as the default. AKI.IO exposes MiniMax M3 only on its native endpoint, so a | ||||||||||||
| 32 | # current non-MiniMax model AKI's own table rates "Supported" is the shim | ||||||||||||
| 33 | # default. Verified live 2026-09-10: the /anthropic shim answers gpt-oss-120b | ||||||||||||
| 34 | # and echoes it back as $response->model. -- karr k132 | ||||||||||||
| 35 | 18 | ▶ | sub default_model { 'gpt-oss-120b' } | ||||||||||
|
Subroutine
default_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 36 | |||||||||||||
| 37 | |||||||||||||
| 38 | 2 | ▶ | sub api_key_env { 'LANGERTHA_AKI_API_KEY' } | ||||||||||
|
Subroutine
api_key_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 39 | |||||||||||||
| 40 | # AKI.IO's /anthropic shim spells the cache read the Anthropic way but counts it | ||||||||||||
| 41 | # inside input_tokens: the captures t/data/akianthropic_chat_response.json and | ||||||||||||
| 42 | # akiopenai_chat_response.json answer the same request with input_tokens 65 + | ||||||||||||
| 43 | # cache_read_input_tokens 64 here and prompt_tokens 65 / cached_tokens 64 on the | ||||||||||||
| 44 | # OpenAI face. Without this, Pricing with a cache rate bills the 64 reads twice. | ||||||||||||
| 45 | # -- ADR 0031, k265 | ||||||||||||
| 46 | 12 | ▶ | sub _usage_input_includes_cache { 1 } | ||||||||||
|
Subroutine
_usage_input_includes_cache: called CC=1 SCAR=0.0
| |||||||||||||
| 47 | |||||||||||||
| 48 | # AKI.IO's machine-readable agent config states "default_max_output_tokens": | ||||||||||||
| 49 | # 8192, which is below the documented output limit of every listed model. The | ||||||||||||
| 50 | # Anthropic dialect requires max_tokens on every request, so this overrides the | ||||||||||||
| 51 | # conservative 1024 of Langertha::Role::AnthropicCompatible. | ||||||||||||
| 52 | 64 | ▶ | sub default_response_size { 8192 } | ||||||||||
|
Subroutine
default_response_size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 53 | |||||||||||||
| 54 | # Static list from the model table on | ||||||||||||
| 55 | # https://aki.io/docs/compatibility/anthropic-api-compatibility/ — AKI.IO's own | ||||||||||||
| 56 | # docs disagree about model discovery (the Anthropic page points at | ||||||||||||
| 57 | # /anthropic/v1/models, the agent integration guide says discovery runs through | ||||||||||||
| 58 | # the OpenAI-compatible /openai/v1/models), so this engine does not depend on | ||||||||||||
| 59 | # either endpoint. Use Langertha::Engine::AKIOpenAI->list_models for a live list. | ||||||||||||
| 60 | 1 | ▶ | sub _build_static_models {[ | ||||||||||
|
Subroutine
_build_static_models: called CC=1 SCAR=0.0
| |||||||||||||
| 61 | 1 | { id => 'apertus-chat-70b' }, | |||||||||||
| 62 | { id => 'gpt-oss-120b' }, | ||||||||||||
| 63 | { id => 'gemma4-26b' }, | ||||||||||||
| 64 | { id => 'kimi-k2.7-code-1100b' }, | ||||||||||||
| 65 | { id => 'llama3-chat-8b' }, | ||||||||||||
| 66 | { id => 'llama3-chat-70b' }, | ||||||||||||
| 67 | { id => 'minimax-m2.5-230b' }, | ||||||||||||
| 68 | { id => 'mistral4-119b' }, | ||||||||||||
| 69 | { id => 'qwen3.6-35b' }, | ||||||||||||
| 70 | ]} | ||||||||||||
| 71 | |||||||||||||
| 72 | 181 | ▶ | around engine_capabilities => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 73 | 181 | my ( $orig, $self, @rest ) = @_; | |||||||||||
| 74 | 181 | my $caps = $self->$orig(@rest); | |||||||||||
| 75 | # image_input (k266, ADR 0019): vision is undocumented / unverified on this face, so no claim. | ||||||||||||
| 76 | 181 | delete $caps->{image_input}; | |||||||||||
| 77 | # Tool-result images (karr k359): the shim takes an image inside a tool_result | ||||||||||||
| 78 | # without error but the model does not see it. Live probe 2026-09-30 | ||||||||||||
| 79 | # (llm-advisor, aki.io/anthropic/v1/messages): qwen3.6-35b read a plain | ||||||||||||
| 80 | # user-message image correctly (16x16 red -> 'Red'), but the same kind of image | ||||||||||||
| 81 | # inside a tool_result came back as 'White' (16x16 red) and 'Black' (64x64 | ||||||||||||
| 82 | # green), with ~340 input tokens whatever the image size; gpt-oss-120b answered | ||||||||||||
| 83 | # 200 and saw only the text. The k336 placeholder at least says an image | ||||||||||||
| 84 | # was there, so tool_result_images is cleared even if an image_input row is | ||||||||||||
| 85 | # added for this face later (ADR 0039, k380). | ||||||||||||
| 86 | 181 | delete $caps->{tool_result_images}; | |||||||||||
| 87 | 181 | return $caps; | |||||||||||
| 88 | 16 | }; | |||||||||||
| 89 | |||||||||||||
| 90 | # Source blocks in a tool_result (karr k364, k366): live probes 2026-09-30 | ||||||||||||
| 91 | # (llm-advisor, aki.io/anthropic/v1/messages) -- a text document answered | ||||||||||||
| 92 | # HTTP 529 {"type":"overloaded_error","message":"Unsupported content type: | ||||||||||||
| 93 | # document"} (qwen3.6-35b), and a search_result block {source, title, | ||||||||||||
| 94 | # content:[text]} answered 529 "Unsupported content type: search_result" | ||||||||||||
| 95 | # (qwen3.6-35b twice, gpt-oss-120b once). Deterministic on AKI, not a retry | ||||||||||||
| 96 | # signal: either breaks the tool-loop turn. An MCP text resource therefore goes | ||||||||||||
| 97 | # out as a text block, a PDF as the placeholder, a native document or | ||||||||||||
| 98 | # search_result as its text. (is_error: true in the same probes was accepted | ||||||||||||
| 99 | # and silently ignored -- 200, same answer and input tokens as without it -- | ||||||||||||
| 100 | # so it is still sent, like on every other shim; k366.) | ||||||||||||
| 101 | 190 | ▶ | sub _tool_result_source_blocks_on_wire { 0 } | ||||||||||
|
Subroutine
_tool_result_source_blocks_on_wire: called CC=1 SCAR=0.0
| |||||||||||||
| 102 | |||||||||||||
| 103 | 16 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | 16 | 1; | |||||||||||
| 107 | |||||||||||||
| 108 | __END__ | ||||||||||||