| 1 | package Langertha::Engine::Perplexity; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Perplexity Agent API (search-augmented) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 22 | our $VERSION = '0.503'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 22 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 22 | extends 'Langertha::Engine::Remote'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # Lean Agent-API engine (ADR 0016): parent = Remote for auth + HTTP + JSON only, | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # NOT OpenAIBase — the Agent API is the Open-Responses envelope, not | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # /chat/completions, so composing the OpenAI dialect (and its embeddings / | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # whisper / model-list baggage, plus the inherited-but-wrong capability flags | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # k138 catalogued) would be dishonest. The envelope lives in | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # Role::ResponsesCompatible, composed here exactly as AnthropicBase composes | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # Role::AnthropicCompatible. Role::ReasoningEffort::_build_reasoning_wire_format | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # and Role::Tools::_build_tool_wire_format default to 'openai'; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # ResponsesCompatible (composed last) supplies 'responses' for both (ADR 0015 | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # -excludes canon). Role::Tools: the Agent API takes client-executed | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # type:function tools (karr k213); its built-in tools are not modelled here. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 22 | with 'Langertha::Role::Models', | |||||||||||||||||||||||||||||||||||||||||
| 21 | 'Langertha::Role::Temperature', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 'Langertha::Role::ReasoningEffort' => { -excludes => ['_build_reasoning_wire_format'] }, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 'Langertha::Role::Tools' => { -excludes => ['_build_tool_wire_format'] }, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 'Langertha::Role::ResponseSize', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 'Langertha::Role::SystemPrompt', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 'Langertha::Role::ResponseFormat', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'Langertha::Role::Streaming', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # Role::Chat::content_format defaults to 'openai'; ResponsesCompatible supplies 'responses'. | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 'Langertha::Role::Chat' => { -excludes => ['content_format'] }, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 'Langertha::Role::StaticModels', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'Langertha::Role::ImageInput', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 'Langertha::Role::ResponsesCompatible'; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | has '+url' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 69 | ▶ | default => sub { 'https://api.perplexity.ai' }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | has api_key => ( | |||||||||||||||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub _build_api_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_api_key: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | return $ENV{LANGERTHA_PERPLEXITY_API_KEY} | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | || croak "".(ref $self)." requires LANGERTHA_PERPLEXITY_API_KEY or api_key set"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ENV{'LANGERTHA_PERPLEXITY_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
MC/DC0%0/2
$ENV{'LANGERTHA_PERPLEXITY_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
$ENV{'LANGERTHA_PERPLEXITY_API_KEY'}
croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
Truth table33%1/3
A || B
A= $ENV{'LANGERTHA_PERPLEXITY_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 102 | ▶ | sub update_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_request: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 102 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 102 | my $key = $self->api_key; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 102 | ▶ | $request->header('Authorization', 'Bearer '.$key) if defined $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 39 | ▶ | sub default_model { 'sonar' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_model: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # The four user-facing model ids, unchanged from the Sonar lineup. They are | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # selectors only: _responses_model_kwargs maps each onto a preset for the wire. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub _build_static_models {[ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_static_models: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | { id => 'sonar' }, | |||||||||||||||||||||||||||||||||||||||||
| 64 | { id => 'sonar-pro' }, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | { id => 'sonar-reasoning-pro' }, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | { id => 'sonar-deep-research' }, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ]} | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # Doc-recommended model -> preset mapping (migrate-from-sonar guide 2026-09-10; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # live-confirmed k147, 2026-09-14). A preset is a routing label, not a model id: | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # fast, low and medium all resolved to openai/gpt-5.6-luna on the wire, so the | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # base model behind a preset is Perplexity's to change -- which is why the engine | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # reports whatever $response->model returns rather than mapping it back (by | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # 2026-09-29, k232, fast already resolved to openai/gpt-6-luna). high | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # (sonar-deep-research) was not exercised (cost). reasoning.effort on the | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # fast/low presets is ACCEPTED (HTTP 200, echoed as reasoning:{effort}) but | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # spends no reasoning tokens there -- honored-as-accepted, a no-op on the | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # non-reasoning presets, never a 400. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 22 | my %MODEL_TO_PRESET = ( | |||||||||||||||||||||||||||||||||||||||||
| 80 | 'sonar' => 'fast', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 'sonar-pro' => 'low', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 'sonar-reasoning-pro' => 'medium', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 'sonar-deep-research' => 'high', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # Exactly one of model / models / preset is required. Emit the preset for a | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # known sonar id (presets bundle web_search + citations); pass anything else | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # straight through as `model` so a caller can target an explicit Agent | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # model/preset by name. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 106 | ▶ | sub _responses_model_kwargs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_responses_model_kwargs: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 106 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 106 | ▶ | my $model = $self->chat_model // $self->default_model; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->chat_model // $self->default_model
MC/DC0%0/2
$self->chat_model // $self->default_model
$self->chat_model
$self->default_model
Truth table33%1/3
A // B
A= $self->chat_modelB= $self->default_model
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 106 | ▶ | if ( my $preset = $MODEL_TO_PRESET{$model} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 104 | return ( preset => $preset ); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | return ( model => $model ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # Structured output stays in the Chat-Completions shape at the TOP level of the | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # body ({type:json_schema,json_schema:{name,schema,strict?}}) — NOT under | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # text.format the way OpenAI's Responses engine wants it. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # Live-confirmed (k147): the top-level response_format=json_schema slot is | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # honored, `strict` is enforced (the reply is exactly the schema, no extra | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # keys), structured JSON is returned, and search still runs alongside it. The | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # response_format.type enum is {json_schema,text} (see the json_object | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # correction below). | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 9 | ▶ | sub _responses_format_kwargs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_responses_format_kwargs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 9 | my ( $self, $rf ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 9 | return ( response_format => $rf ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # Agent API input items are typed {type:"message",role,content}. Live-confirmed | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # (k147): a bare {role,content} item (no type) is ALSO accepted (HTTP 200), so | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # type:message is a safe superset rather than a hard requirement — stamp it | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # anyway, the explicit form the docs show. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 122 | ▶ | sub _normalize_input_item { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_input_item: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 122 | my ( $self, $msg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 122 | return { type => 'message', %$msg }; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # The Agent API is not an OpenAPI-spec engine here: POST the built body straight | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # to /v1/agent (Remote's generate_http_request), rather than resolving an | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # operation id against a spec the way OpenAIResponses does. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # Live-confirmed (k147): creation is POST /v1/agent (HTTP 200). The reply is an | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # object:"response" with a resp_ id, store:true and background:false — the | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # Open-Responses store shape — so retrieval would follow /v1/responses/{id}, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # not /v1/agent/{id}. Retrieve/background is not implemented here and was not | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # exercised (stateful; no cheap probe). | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 102 | ▶ | sub _responses_dispatch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_responses_dispatch: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 102 | my ( $self, $response_call, @request_args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 102 | return $self->generate_http_request( | |||||||||||||||||||||||||||||||||||||||||
| 132 | POST => $self->url.'/v1/agent', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | $response_call, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | @request_args, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | # Citations. The classic Sonar top-level citations[] is gone; the Agent API | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # carries sources in an output[] item of type search_results, each result a | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # {id,url,title,snippet,date,last_updated,source} hash. Lift them onto | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # Response.citations. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # Live-confirmed (k147): inline markers are [1] (NOT [web:1]); the message | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # output_text part carries an annotations[] that came back empty, so the | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # search_results block is the authoritative source list, exactly as assumed | ||||||||||||||||||||||||||||||||||||||||||
| 145 | # here. A structured (json_schema) reply still emits the search_results block. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 49 | ▶ | sub _responses_extra_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_responses_extra_fields: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 49 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 49 | my @citations; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 49 | ▶ | for my $item ( @{ $data->{output} // [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$data{"output"} // []
MC/DC100%1/1
$$data{"output"} // []
$$data{"output"}
Truth table100%2/2
A
A= $$data{"output"}
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 62 | ▶ | next unless ref($item) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 62 | ▶ | next unless ( $item->{type} // '' ) eq 'search_results'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$item{"type"} // ""
MC/DC0%0/1
$$item{"type"} // ""
$$item{"type"}
Truth table50%1/2
A
A= $$item{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 11 | ▶ | push @citations, @{ $item->{results} // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$item{"results"} // []
MC/DC0%0/1
$$item{"results"} // []
$$item{"results"}
Truth table50%1/2
A
A= $$item{"results"}
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 49 | ▶ | return @citations ? ( citations => \@citations ) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # Agent API echo filter (karr k213, ADR 0020 k213 Update). The Agent input is | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # a closed oneOf of message | function_call | function_call_output, and a | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # message part is only input_text / input_image (OpenAPI for POST /v1/agent, | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # fetched 2026-09-25). Live-confirmed (k232, 2026-09-29): the echo this builds | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # -- the call verbatim with its fc_ id and status, a preamble flattened to | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # string content, search_results left out -- is accepted (HTTP 200); captures in | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # t/data/perplexity_agent_*. The Responses echo replays every | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # output[] item, which on a preset turn includes search_results / | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # fetch_url_results / *_results / mcp_* items and an assistant message of | ||||||||||||||||||||||||||||||||||||||||||
| 166 | # output_text parts -- all off-schema as input. Keep the calls (thought_signature | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # included, as Perplexity's own sample replays them), flatten an assistant | ||||||||||||||||||||||||||||||||||||||||||
| 168 | # message to its text, drop everything else. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 22 | ▶ | sub _responses_echo_item { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_responses_echo_item: called CC=12 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 22 | my ( $self, $item ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 22 | ▶ | my $type = $item->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$item{"type"} // ""
MC/DC0%0/1
$$item{"type"} // ""
$$item{"type"}
Truth table50%1/2
A
A= $$item{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 22 | ▶ | return $item if $type eq 'function_call' || $type eq 'function_call_output'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "function_call" or $type eq "function_call_output"
MC/DC50%1/2
$type eq "function_call" or $type eq "function_call_output"
$type eq "function_call"
$type eq "function_call_output"
Truth table66%2/3
A or B
A= $type eq "function_call"B= $type eq "function_call_output"
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | ▶ | return () unless $type eq 'message'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | my $content = $item->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | my $text = ref $content eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | ? join( '', map { $_->{text} // '' } | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$_{"text"} // ""
MC/DC0%0/1
$$_{"text"} // ""
$$_{"text"}
Truth table50%1/2
A
A= $$_{"text"}
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | grep { ref $_ eq 'HASH' && ( $_->{type} // '' ) eq 'output_text' } @$content ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition28%2/7
ref $_ eq 'HASH' && ($$_{'type'} // '') eq 'output_text'
$$_{"type"} // ""
$content // ""
MC/DC0%0/2
ref $_ eq 'HASH' && ($$_{'type'} // '') eq 'output_text'
ref $_ eq 'HASH'
$$_{"type"}
MC/DC0%0/1
$content // ""
$content
Truth table33%1/3
A && B
A= ref $_ eq 'HASH'B= $$_{"type"}
Truth table0%0/2
A
A= $content
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | : ( $content // '' ); | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | return () unless length $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | return { type => 'message', role => ( $item->{role} // 'assistant' ), content => $text }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$item{"role"} // "assistant"
MC/DC0%0/1
$$item{"role"} // "assistant"
$$item{"role"}
Truth table50%1/2
A
A= $$item{"role"}
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | # The Agent API's response_format enum is {json_schema,text} — no json_object | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # (live-confirmed k147: a json_object body -> HTTP 400 "validation failed: | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # response_format.type must be one of json_schema, text"), so clear the flag | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # Role::ResponseFormat advertises by default. The Agent request schema has no | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # tool_choice and no parallel_tool_calls field (karr k213, docs only), so clear | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # every tool_choice_* flag and parallel_tool_use that Role::Tools brings: the | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # envelope then never sends either field, and with tool_choice_named off chat_f | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # still reroutes a forced tool through json_schema (Perplexity stays the ADR | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # 0005 direction-1 exemplar). Everything else is honest by composition: no | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # Role::PromptCache (prompt_cache / prompt_cache_key stay off — caching is | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # automatic), no Role::ServerTools, Role::ReasoningEffort composed so | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # reasoning_effort is on (wire reasoning.effort via the responses format). | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 402 | ▶ | around engine_capabilities => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 402 | my ( $orig, $self, @rest ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 402 | my $caps = $self->$orig(@rest); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 402 | delete $caps->{$_} for qw( | |||||||||||||||||||||||||||||||||||||||||
| 199 | response_format_json_object | ||||||||||||||||||||||||||||||||||||||||||
| 200 | tool_choice_auto tool_choice_any tool_choice_none tool_choice_named | ||||||||||||||||||||||||||||||||||||||||||
| 201 | parallel_tool_use | ||||||||||||||||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 402 | return $caps; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 22 | }; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # image_input (k266, ADR 0019 k266 Update): the Agent API takes input_image | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # parts (k267), but a sonar id is a preset whose base model is Perplexity's to | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # change, so only an explicit third-party id from an all-vision family claims | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # (llm-advisor, docs only, 2026-09-25). Open-weight gpt-oss is text-only. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 370 | ▶ | sub model_capability_corrections { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_capability_corrections: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 370 | qr/\A/ => { image_input => 0 }, | |||||||||||||||||||||||||||||||||||||||||
| 213 | qr{\A(?:openai|anthropic|google)/} => { image_input => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | qr{\Aopenai/gpt-oss} => { image_input => 0 }, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # Tool-result PDFs (karr k361): the Agent API's FunctionCallOutputInput.output | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # is "a JSON string or an array of input_text and input_image content parts", | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # and no input schema lists input_file (docs.perplexity.ai/api-reference/ | ||||||||||||||||||||||||||||||||||||||||||
| 221 | # agent-post, fetched 2026-09-30), so a PDF stays the k336 placeholder while | ||||||||||||||||||||||||||||||||||||||||||
| 222 | # OpenAIResponses sends it as input_file. Spelled out (the Role::Tools default | ||||||||||||||||||||||||||||||||||||||||||
| 223 | # is 0 too) because this is where the shared Responses envelope diverges. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 12 | ▶ | sub _tool_result_pdf_on_wire { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tool_result_pdf_on_wire: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # Rate limit (karr k356, ADR 0022): the Agent API sends x-ratelimit-limit / | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # -remaining / -reset / -used with no -requests / -tokens suffix, and the Remote | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # fallback reads only Retry-After. Read here, not in a shared parser: on | ||||||||||||||||||||||||||||||||||||||||||
| 229 | # Perplexity -reset is an epoch-seconds instant (the k232 captures put it one | ||||||||||||||||||||||||||||||||||||||||||
| 230 | # second after their own Date header), while other senders of the same names use | ||||||||||||||||||||||||||||||||||||||||||
| 231 | # other kinds (OpenRouter an epoch-ms, the IETF RateLimit draft delta-seconds), | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # and ADR 0022 declines guessing the kind by magnitude. used=1 after one request | ||||||||||||||||||||||||||||||||||||||||||
| 233 | # makes it the requests bucket. -used stays in raw; retry_after is derived from | ||||||||||||||||||||||||||||||||||||||||||
| 234 | # raw as on every engine. | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 44 | ▶ | around _parse_rate_limit_headers => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 44 | my ( $orig, $self, $http_response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 44 | require Langertha::RateLimit; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 44 | require Langertha::Moment; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 44 | my %raw = Langertha::RateLimit::_collect_headers($http_response); | |||||||||||||||||||||||||||||||||||||||||
| 240 | 44 | my ( $limit, $remaining, $reset ) = @raw{ map { "x-ratelimit-$_" } qw( limit remaining reset ) }; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 44 | ▶ | return $self->$orig($http_response) unless defined $limit || defined $remaining || defined $reset; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $limit or defined $remaining or defined $reset
defined $limit or defined $remaining
MC/DC33%1/3
defined $limit or defined $remaining or defined $reset
defined $limit
defined $remaining
defined $reset
Truth table50%2/4
A or B or C
A= defined $limitB= defined $remainingC= defined $reset
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 14 | my $reset_at = Langertha::Moment->from_wire($reset); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 14 | ▶ | return Langertha::RateLimit->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | received => Langertha::Moment->now_utc, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | ( defined $limit ? ( requests_limit => $limit + 0 ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ( defined $remaining ? ( requests_remaining => $remaining + 0 ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 247 | ( defined $reset ? ( requests_reset => $reset ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 248 | ( defined $reset_at ? ( requests_reset_at => $reset_at ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 249 | raw => \%raw, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 22 | }; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 22 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 22 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | Langertha::Engine::Perplexity - Perplexity Agent API (search-augmented) | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | version 0.503 | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | use Langertha::Engine::Perplexity; | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | my $perplexity = Langertha::Engine::Perplexity->new( | ||||||||||||||||||||||||||||||||||||||||||
| 277 | api_key => $ENV{PERPLEXITY_API_KEY}, | ||||||||||||||||||||||||||||||||||||||||||
| 278 | model => 'sonar-pro', | ||||||||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | my $response = $perplexity->simple_chat('What are the latest Perl releases?'); | ||||||||||||||||||||||||||||||||||||||||||
| 282 | print $response; # the answer text | ||||||||||||||||||||||||||||||||||||||||||
| 283 | print $response->citations; # ArrayRef of search sources | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # Streaming | ||||||||||||||||||||||||||||||||||||||||||
| 286 | $perplexity->simple_chat_stream(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | print shift->content; | ||||||||||||||||||||||||||||||||||||||||||
| 288 | }, 'Summarize recent Perl news'); | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | # Async with Future::AsyncAwait | ||||||||||||||||||||||||||||||||||||||||||
| 291 | use Future::AsyncAwait; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | my $response = await $perplexity->simple_chat_f('What is new in Perl?'); | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | Provides access to Perplexity's B<Agent API> (C<POST /v1/agent>), the successor | ||||||||||||||||||||||||||||||||||||||||||
| 297 | to the retired Sonar Chat Completions surface (Sonar Chat Completions reached | ||||||||||||||||||||||||||||||||||||||||||
| 298 | end of life 2026-09-27). The Agent API speaks the Open-Responses wire envelope | ||||||||||||||||||||||||||||||||||||||||||
| 299 | (C<input> / C<instructions> / typed C<output[]> / C<input_tokens> usage), not | ||||||||||||||||||||||||||||||||||||||||||
| 300 | C</chat/completions>, so this engine composes | ||||||||||||||||||||||||||||||||||||||||||
| 301 | L<Langertha::Role::ResponsesCompatible> (shared with | ||||||||||||||||||||||||||||||||||||||||||
| 302 | L<Langertha::Engine::OpenAIResponses>) over a bare | ||||||||||||||||||||||||||||||||||||||||||
| 303 | L<Langertha::Engine::Remote> for Bearer auth and HTTP. | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | Perplexity models are search-augmented LLMs with real-time web access; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | responses carry L<Langertha::Response/citations> alongside the generated text. | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | =head2 Models and presets | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | The four user-facing model ids are kept as the selector; each maps to an Agent | ||||||||||||||||||||||||||||||||||||||||||
| 311 | API B<preset>, which is what actually reaches the wire. Presets bundle the | ||||||||||||||||||||||||||||||||||||||||||
| 312 | web_search tool and inline citations automatically — a bare model call on the | ||||||||||||||||||||||||||||||||||||||||||
| 313 | Agent API no longer searches (web search became opt-in), so the preset path is | ||||||||||||||||||||||||||||||||||||||||||
| 314 | what preserves Perplexity's search+citations identity. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | sonar -> preset "fast" | ||||||||||||||||||||||||||||||||||||||||||
| 317 | sonar-pro -> preset "low" | ||||||||||||||||||||||||||||||||||||||||||
| 318 | sonar-reasoning-pro -> preset "medium" | ||||||||||||||||||||||||||||||||||||||||||
| 319 | sonar-deep-research -> preset "high" | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | C<$response-E<gt>model> reports the real model the chosen preset ran — a preset | ||||||||||||||||||||||||||||||||||||||||||
| 322 | is a routing label, not a fixed model (in mid-September 2026 C<fast>, C<low> and | ||||||||||||||||||||||||||||||||||||||||||
| 323 | C<medium> all resolved to C<openai/gpt-5.6-luna> on the wire; by 2026-09-29 | ||||||||||||||||||||||||||||||||||||||||||
| 324 | C<fast> resolved to C<openai/gpt-6-luna>), so read the model off the response | ||||||||||||||||||||||||||||||||||||||||||
| 325 | rather than inferring it from the preset. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | =head2 Capabilities | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | Client function tools work: pass C<tools> to C<chat_f>, or set | ||||||||||||||||||||||||||||||||||||||||||
| 330 | C<mcp_servers> and use C<chat_with_tools_f>. They go out as flat | ||||||||||||||||||||||||||||||||||||||||||
| 331 | C<< { type => 'function', name, description, parameters } >> tools, the | ||||||||||||||||||||||||||||||||||||||||||
| 332 | model's C<function_call> items land on L<Langertha::Response/tool_calls>, and | ||||||||||||||||||||||||||||||||||||||||||
| 333 | the tool loop answers them with C<function_call_output> items. Perplexity never | ||||||||||||||||||||||||||||||||||||||||||
| 334 | runs a function tool itself. A preset still runs its own C<web_search> | ||||||||||||||||||||||||||||||||||||||||||
| 335 | alongside your tools (presets merge tools). The echo of a tool turn keeps only | ||||||||||||||||||||||||||||||||||||||||||
| 336 | what the Agent input accepts: the function calls and the assistant's text; the | ||||||||||||||||||||||||||||||||||||||||||
| 337 | search results and other built-in tool items are left out. The call turn, its | ||||||||||||||||||||||||||||||||||||||||||
| 338 | echo (the call with its C<id> and C<status>, then the C<function_call_output>) | ||||||||||||||||||||||||||||||||||||||||||
| 339 | and a streamed call turn were checked against the live API (2026-09-29). For a | ||||||||||||||||||||||||||||||||||||||||||
| 340 | turn with search results and an assistant preamble (a constructed turn: the | ||||||||||||||||||||||||||||||||||||||||||
| 341 | model did not produce one live), only this is live-confirmed: the filtered echo | ||||||||||||||||||||||||||||||||||||||||||
| 342 | is accepted with HTTP 200. That the Agent input rejects the unfiltered items | ||||||||||||||||||||||||||||||||||||||||||
| 343 | comes from Perplexity's documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | There is no C<tool_choice> and no C<parallel_tool_calls> on the Agent API, so | ||||||||||||||||||||||||||||||||||||||||||
| 346 | every C<tool_choice_*> capability and C<parallel_tool_use> are off and neither | ||||||||||||||||||||||||||||||||||||||||||
| 347 | field is ever sent (a forced choice that cannot be sent carps). C<tool_choice | ||||||||||||||||||||||||||||||||||||||||||
| 348 | =E<gt> 'none'> is honored by leaving the request's tools out (with a carp); a | ||||||||||||||||||||||||||||||||||||||||||
| 349 | choice Langertha cannot read is dropped with a carp. A request without tools | ||||||||||||||||||||||||||||||||||||||||||
| 350 | may still carry earlier C<function_call> and C<function_call_output> items; the | ||||||||||||||||||||||||||||||||||||||||||
| 351 | Agent API accepts them (checked live, 2026-09-29). Perplexity's | ||||||||||||||||||||||||||||||||||||||||||
| 352 | built-in tools (C<web_search>, C<fetch_url>, C<sandbox>, ...) are not modelled | ||||||||||||||||||||||||||||||||||||||||||
| 353 | yet; a native hash of one in C<tools> is sent as given. | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | No C<json_object> mode: the only structured C<response_format> the Agent API | ||||||||||||||||||||||||||||||||||||||||||
| 356 | accepts is C<json_schema> (the C<type> enum is C<json_schema>/C<text>; a | ||||||||||||||||||||||||||||||||||||||||||
| 357 | C<json_object> body is rejected with HTTP 400). A forced named tool still | ||||||||||||||||||||||||||||||||||||||||||
| 358 | works as structured output — C<chat_f> rewrites it into a top-level | ||||||||||||||||||||||||||||||||||||||||||
| 359 | C<response_format=json_schema> plus a synthetic L<Langertha::ToolCall> (ADR | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0005 rewrite direction 1; Perplexity remains its exemplar), and C<strict> is | ||||||||||||||||||||||||||||||||||||||||||
| 361 | enforced on the returned JSON. C<reasoning_effort> B<is> accepted (wire | ||||||||||||||||||||||||||||||||||||||||||
| 362 | C<reasoning.effort>), though the non-reasoning presets (C<fast>/C<low>) echo it | ||||||||||||||||||||||||||||||||||||||||||
| 363 | back without spending reasoning tokens. Prompt caching is automatic (no | ||||||||||||||||||||||||||||||||||||||||||
| 364 | request-side key). | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | Limitations: embeddings and transcription are not supported. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | Get your API key at L<https://www.perplexity.ai/settings/api> and set | ||||||||||||||||||||||||||||||||||||||||||
| 369 | C<LANGERTHA_PERPLEXITY_API_KEY>. | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | =head2 api_key | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | Perplexity API key, sent as C<Authorization: Bearer>. Defaults to | ||||||||||||||||||||||||||||||||||||||||||
| 374 | C<LANGERTHA_PERPLEXITY_API_KEY>. | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | =head2 update_request | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | Adds the C<Authorization: Bearer {api_key}> header. Auth is unchanged from the | ||||||||||||||||||||||||||||||||||||||||||
| 379 | Sonar surface — only the endpoint and body shape moved to the Agent API. | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | =item * L<Langertha::Role::ResponsesCompatible> - the Open-Responses wire envelope this composes | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | =item * L<Langertha::Engine::OpenAIResponses> - the other Responses-envelope consumer | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | =item * L<https://docs.perplexity.ai/docs/agent-api/migrate-from-sonar/overview> - Sonar -> Agent API migration guide | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | =item * L<https://status.perplexity.com/> - Perplexity service status | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | =head2 Issues | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||||||||||||
| 400 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | =head2 IRC | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 419 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||||||||||||||||