blib/lib/Langertha/Skeid/Protocol/Anthropic/Stream.pm

filter: Statementstmt 100% 95 / 95 Branchbran 82.6% 38 / 46 Conditioncond 71.4% 35 / 49 MC/DCmcdc 38.4% 10 / 26 Subroutinesub 100% 13 / 13 Podpod 100% 8 / 8 totaltotal 83.9% 199 / 237 CC 46 SCAR 30.5
CC
46
Cov
88%
delta
33.6
finish
11.3
new
3.3
CRAP 21.1
« blib/lib/Langertha/Skeid/KeyBroker/OpenBao.pm ↑ Summary blib/lib/Langertha/Skeid/UsageStore/DBI.pm »
1 package Langertha::Skeid::Protocol::Anthropic::Stream;
2 50 our $VERSION = '0.003';
3 # ABSTRACT: Rewrites an OpenAI SSE stream as Anthropic streaming events
4 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 50 ▶use Langertha::Skeid::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 50 ▶use Langertha::Skeid::Protocol::Anthropic;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10  
11 73 ▶sub new {
Subroutine new: called CC=3 SCAR=12.0
Pod documented
12 73 my ($class, %args) = @_;
13 return bless {
14 model => ($args{model} // ''),
15 73 ▶ message_id => ($args{message_id} // ('msg_' . int(time * 1000))),
Condition50%2/4
$args{"model"} // ""
l!l
730
$args{"message_id"} // 'msg_' . int(time * 1000)
l!l
073
MC/DC0%0/1
$args{"model"} // ""
$args{"model"}
MC/DC0%0/1
$args{"message_id"} // 'msg_' . int(time * 1000)
$args{"message_id"}
Truth table50%1/2
A
A= $args{"model"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"message_id"}
Aresult
11
00
16 started => 0,
17 finished => 0,
18 errored => 0,
19 output_tokens => 0,
20 input_tokens => 0,
21 stop_reason => undef,
22 finish_reason => undef,
23 text_bytes => 0,
24  
25 # Content-block state. The OpenAI stream numbers parallel tool calls by their position
26 # in tool_calls[i].index; Anthropic numbers content blocks by their own order of
27 # appearance. The two numberings are different, so the translator keeps a map:
28 # tool_blocks keyed by the OpenAI index, each value an {anthropic_index, id, name,
29 # partial_json} record. open_blocks lists the Anthropic indices still awaiting a
30 # content_block_stop; next_index is the Anthropic index the next new block will get.
31 next_index => 0,
32 text_index => undef,
33 text_started => 0,
34 tool_blocks => {},
35 open_blocks => [],
36 }, $class;
37 }
38  
39  
40 53 ▶sub content_type { 'text/event-stream' }
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
41  
42 393 ▶sub _event {
Subroutine _event: called CC=1 SCAR=0.0
43 393 my ($name, $payload) = @_;
44 393 return "event: $name\ndata: " . Langertha::Skeid::Protocol::encode_json_safe($payload) . "\n\n";
45 }
46  
47  
48 60 ▶sub start {
Subroutine start: called CC=2 SCAR=7.0
Pod documented
49 60 my ($self) = @_;
50 60 ▶ return '' if $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} 0 60 60
51 60 $self->{started} = 1;
52  
53 # The SSE event name and the "type" inside its data must agree: the official SDKs dispatch on
54 # the data field, not on the event line, so a message_start carrying type "message" is a
55 # frame they do not recognise as the start of anything.
56 return _event('message_start', {
57 type => 'message_start',
58 message => {
59 id => $self->{message_id},
60 type => 'message',
61 role => 'assistant',
62 model => $self->{model},
63 60 content => [],
64 stop_reason => undef,
65 stop_sequence => undef,
66 usage => { input_tokens => 0, output_tokens => 0 },
67 },
68 });
69 }
70  
71  
72 187 ▶sub delta {
Subroutine delta: called CC=32 SCAR=35.1
Pod documented
73 187 my ($self, $chunk) = @_;
74 187 ▶ return '' unless ref($chunk) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $chunk eq "HASH" 0 187 187
75  
76 187 ▶ return '' if $self->{finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finished"} 0 187 187
77  
78 # Some servers report a failure inside an open stream as a chunk carrying an OpenAI error
79 # object instead of choices. The HTTP status is already 200, so it can only reach an
80 # Anthropic client in-band, as an error event -- and nothing after it (core karr #224).
81 187 ▶ if (ref($chunk->{error}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $chunk->{"error"} eq "HASH") 3 184 187
82 3 ▶ my $message = $chunk->{error}{message} // 'upstream error';
Condition50%1/2
$chunk->{"error"}{"message"} // "upstream error"
l!l
30
MC/DC0%0/1
$chunk->{"error"}{"message"} // "upstream error"
$chunk->{"error"}{"message"}
Truth table50%1/2
A
A= $chunk->{"error"}{"message"}
Aresult
11
00
83 3 return $self->error_event(500, "Upstream error: $message", $chunk->{error}{type});
84 }
85  
86 184 my $out = '';
87 184 ▶ $out .= $self->start unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 51 133 184
88  
89 # Usage can arrive on any chunk and usually arrives on the last one, which is also the
90 # chunk that has no content. Recorded whenever seen, reported at the end.
91 184 ▶ if (my $usage = $chunk->{usage}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $usage = $chunk->{"usage"}) 74 110 184
92 74 ▶ $self->{input_tokens} = 0 + ($usage->{prompt_tokens} // $usage->{input_tokens} // $self->{input_tokens});
Condition83%5/6
($usage->{"prompt_tokens"} // $usage->{"input_tokens"}) // $self->{"input_tokens"}
l!l&&r!l&&!r
7130
$usage->{"prompt_tokens"} // $usage->{"input_tokens"}
l!l&&r!l&&!r
6833
MC/DC0%0/3
($usage->{"prompt_tokens"} // $usage->{"input_tokens"}) // $self->{"input_tokens"}
$usage->{"prompt_tokens"} $usage->{"input_tokens"} $self->{"input_tokens"}
Truth table75%3/4
A // B // C
A= $usage->{"prompt_tokens"}B= $usage->{"input_tokens"}C= $self->{"input_tokens"}
ABCresult
1XX1
01X1
0011
0000
93 74 ▶ $self->{output_tokens} = 0 + ($usage->{completion_tokens} // $usage->{output_tokens} // $self->{output_tokens});
Condition83%5/6
($usage->{"completion_tokens"} // $usage->{"output_tokens"}) // $self->{"output_tokens"}
l!l&&r!l&&!r
7103
$usage->{"completion_tokens"} // $usage->{"output_tokens"}
l!l&&r!l&&!r
6833
MC/DC66%2/3
($usage->{"completion_tokens"} // $usage->{"output_tokens"}) // $self->{"output_tokens"}
$usage->{"completion_tokens"} $usage->{"output_tokens"} $self->{"output_tokens"}
Truth table75%3/4
A // B // C
A= $usage->{"completion_tokens"}B= $usage->{"output_tokens"}C= $self->{"output_tokens"}
ABCresult
1XX1
01X1
0011
0000
94 }
95  
96 184 ▶ my $choice = (ref($chunk->{choices}) eq 'ARRAY' ? $chunk->{choices}[0] : undef) || {};
Branch: 1 branch
BranchTrueFalseTotal
ref $chunk->{'choices'} eq 'ARRAY' ? : 184 0 184
Condition50%1/2
(ref $chunk->{'choices'} eq 'ARRAY' ? $chunk->{'choices'}[0] : undef) || {}
l!l
1840
MC/DC0%0/1
(ref $chunk->{'choices'} eq 'ARRAY' ? $chunk->{'choices'}[0] : undef) || {}
(ref $chunk->{'choices'} eq 'ARRAY' ? $chunk->{'choices'}[0] : undef)
Truth table50%1/2
A
A= (ref $chunk->{'choices'} eq 'ARRAY' ? $chunk->{'choices'}[0] : undef)
Aresult
11
00
97 184 ▶ if (defined(my $reason = $choice->{finish_reason})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $reason = $choice->{"finish_reason"})) 36 148 184
98 36 $self->{finish_reason} = $reason;
99 36 ▶ $self->{stop_reason} = $reason eq 'tool_calls' ? 'tool_use'
Branch: 2 branches
BranchTrueFalseTotal
$reason eq 'tool_calls' ? : 10 26 36
$reason eq 'length' ? : 2 24 26
100 : $reason eq 'length' ? 'max_tokens'
101 : 'end_turn';
102 }
103  
104 184 ▶ my $delta = $choice->{delta} || {};
Condition100%2/2
$choice->{'delta'} || {}
l!l
17212
MC/DC100%1/1
$choice->{'delta'} || {}
$choice->{'delta'}
Truth table100%2/2
A
A= $choice->{'delta'}
Aresult
11
00
105  
106 # Text content. The first text delta opens a text block at the next free Anthropic index;
107 # later deltas extend it.
108 184 my $text = $delta->{content};
109 184 ▶ if (defined($text) && length($text)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text and length $text) 89 95 184
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
94189
MC/DC100%2/2
defined $text and length $text
defined $text length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
110 89 ▶ if (!$self->{text_started}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"text_started"}) 52 37 89
111 52 $self->{text_index} = $self->{next_index}++;
112 52 $self->{text_started} = 1;
113 52 push @{$self->{open_blocks}}, $self->{text_index};
114 $out .= _event('content_block_start', {
115 type => 'content_block_start',
116 index => $self->{text_index},
117 52 content_block => { type => 'text', text => '' },
118 });
119 }
120 89 $self->{text_bytes} += Langertha::Skeid::Protocol::utf8_length($text);
121 $out .= _event('content_block_delta', {
122 type => 'content_block_delta',
123 index => $self->{text_index},
124 89 delta => { type => 'text_delta', text => $text },
125 });
126 }
127  
128 # Tool calls. OpenAI tracks parallel calls by tool_calls[i].index; Anthropic tracks content
129 # blocks by their own order. The first time we see a new tool_calls index we allocate an
130 # Anthropic block; later arguments-only deltas for the same index extend it with
131 # partial_json.
132 184 ▶ if (ref($delta->{tool_calls}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $delta->{"tool_calls"} eq "ARRAY") 28 156 184
133 28 for my $call (@{$delta->{tool_calls}}) {
134 28 ▶ next unless ref($call) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $call eq "HASH" 0 28 28
135 28 ▶ my $tool_idx = $call->{index} // 0;
Condition50%1/2
$call->{"index"} // 0
l!l
280
MC/DC0%0/1
$call->{"index"} // 0
$call->{"index"}
Truth table50%1/2
A
A= $call->{"index"}
Aresult
11
00
136  
137 # Lazily allocate a content block for this OpenAI tool_call index. The do block
138 # returns a hashref; ||= stores it under tool_blocks{$tool_idx} and binds $block to
139 # the same ref.
140 28 ▶ my $block = $self->{tool_blocks}{$tool_idx} ||= do {
Condition66%2/3
$self->{"tool_blocks"}{$tool_idx} ||= do {
l!l&&r!l&&!r
15130
MC/DC0%0/2
$self->{"tool_blocks"}{$tool_idx} ||= do { my $anthropic_index = $self->{"next_index"}++; push @{$$self{"open_blocks"};}, $anthropic_index; +{"anthropic_index", $anthropic_index, "id", $call->{"id"} // "", "name", $call->{"function"}{"name"} // "", "partial_json", "", "emitted_start", 0} }
$self->{"tool_blocks"}{$tool_idx} do { my $anthropic_index = $self->{"next_index"}++; push @{$$self{"open_blocks"};}, $anthropic_index; +{"anthropic_index", $anthropic_index, "id", $call->{"id"} // "", "name", $call->{"function"}{"name"} // "", "partial_json", "", "emitted_start", 0} }
Truth table66%2/3
A ||= B
A= $self->{"tool_blocks"}{$tool_idx}B= do { my $anthropic_index = $self->{"next_index"}++; push @{$$self{"open_blocks"};}, $anthropic_index; +{"anthropic_index", $anthropic_index, "id", $call->{"id"} // "", "name", $call->{"function"}{"name"} // "", "partial_json", "", "emitted_start", 0} }
ABresult
1X1
011
000
141 13 my $anthropic_index = $self->{next_index}++;
142 13 push @{$self->{open_blocks}}, $anthropic_index;
143 {
144 anthropic_index => $anthropic_index,
145 id => ($call->{id} // ''),
146 13 ▶ name => ($call->{function}{name} // ''),
Condition50%2/4
$call->{"id"} // ""
l!l
130
$call->{"function"}{"name"} // ""
l!l
130
MC/DC0%0/1
$call->{"id"} // ""
$call->{"id"}
MC/DC0%0/1
$call->{"function"}{"name"} // ""
$call->{"function"}{"name"}
Truth table50%1/2
A
A= $call->{"id"}
Aresult
11
00
Truth table50%1/2
A
A= $call->{"function"}{"name"}
Aresult
11
00
147 partial_json => '',
148 emitted_start => 0,
149 };
150 };
151  
152 # The OpenAI convention is the first chunk for a call carries id+name and later
153 # chunks carry only arguments; tolerate either order, fill in whatever this chunk
154 # brought.
155 28 ▶ $block->{id} = $call->{id} if defined $call->{id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $call->{"id"} 13 15 28
156 28 ▶ $block->{name} = $call->{function}{name} if defined $call->{function}{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $call->{"function"}{"name"} 13 15 28
157  
158 28 ▶ unless ($block->{emitted_start}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($block->{"emitted_start"}) 13 15 28
159 13 $block->{emitted_start} = 1;
160 $out .= _event('content_block_start', {
161 type => 'content_block_start',
162 index => $block->{anthropic_index},
163 content_block => {
164 type => 'tool_use',
165 id => $block->{id},
166 name => $block->{name},
167 13 input => {},
168 },
169 });
170 }
171  
172 28 my $args = $call->{function}{arguments};
173 28 ▶ if (defined($args) && length($args)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args and length $args) 20 8 28
Condition66%2/3
defined $args and length $args
!ll&&!rl&&r
0820
MC/DC50%1/2
defined $args and length $args
defined $args length $args
Truth table66%2/3
A and B
A= defined $argsB= length $args
ABresult
0X0
100
111
174 20 $block->{partial_json} .= $args;
175 $out .= _event('content_block_delta', {
176 type => 'content_block_delta',
177 index => $block->{anthropic_index},
178 20 delta => { type => 'input_json_delta', partial_json => $args },
179 });
180 }
181 }
182 }
183  
184 184 return $out;
185 }
186  
187  
188 56 ▶sub finish {
Subroutine finish: called CC=11 SCAR=24.2
Pod documented
189 56 my ($self, %args) = @_;
190 56 ▶ return '' if $self->{finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finished"} 8 48 56
191  
192 48 my $out = '';
193 48 ▶ $out .= $self->start unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 48 48
194 48 $self->{finished} = 1;
195  
196 48 for my $idx (@{$self->{open_blocks}}) {
197 53 $out .= _event('content_block_stop', {
198 type => 'content_block_stop',
199 index => $idx,
200 });
201 }
202 48 @{$self->{open_blocks}} = ();
203  
204 # A stream that emitted tool_use blocks and then finished with 'stop' (gpt-oss on
205 # vLLM-style servers) ends with stop_reason tool_use, the same rule as the non-streaming
206 # translation: tool calls present wins over 'stop' (core k248).
207 48 my $stop_reason = $args{stop_reason};
208 48 ▶ if (!defined $stop_reason) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stop_reason) 48 0 48
209 48 ▶ my $finish_reason = $self->{finish_reason} // 'stop';
Condition100%2/2
$self->{"finish_reason"} // "stop"
l!l
3414
MC/DC100%1/1
$self->{"finish_reason"} // "stop"
$self->{"finish_reason"}
Truth table100%2/2
A
A= $self->{"finish_reason"}
Aresult
11
00
210 48 ▶ $stop_reason = (%{$self->{tool_blocks}} && $finish_reason eq 'stop')
Condition100%2/2
$self->{"stop_reason"} // "end_turn"
l!l
3314
MC/DC100%1/1
$self->{"stop_reason"} // "end_turn"
$self->{"stop_reason"}
Truth table100%2/2
A
A= $self->{"stop_reason"}
Aresult
11
00
211 ? 'tool_use'
212 48 ▶ : ($self->{stop_reason} // 'end_turn');
Branch: 1 branch
BranchTrueFalseTotal
%{$self->{'tool_blocks'};} && $finish_reason eq 'stop' ? : 1 47 48
Condition100%3/3
%{$self->{"tool_blocks"};} and $finish_reason eq "stop"
!ll&&!rl&&r
36111
MC/DC100%2/2
%{$self->{"tool_blocks"};} and $finish_reason eq "stop"
%{$self->{"tool_blocks"};} $finish_reason eq "stop"
Truth table100%3/3
A and B
A= %{$self->{"tool_blocks"};}B= $finish_reason eq "stop"
ABresult
0X0
100
111
213 }
214  
215 $out .= _event('message_delta', {
216 type => 'message_delta',
217 delta => {
218 stop_reason => $stop_reason,
219 stop_sequence => undef,
220 },
221 48 ▶ usage => { output_tokens => 0 + ($args{output_tokens} // $self->{output_tokens} // 0) },
Condition40%2/5
($args{"output_tokens"} // $self->{"output_tokens"}) // 0
l!l
480
$args{"output_tokens"} // $self->{"output_tokens"}
l!l&&r!l&&!r
0480
MC/DC0%0/2
($args{"output_tokens"} // $self->{"output_tokens"}) // 0
$args{"output_tokens"} $self->{"output_tokens"}
Truth table33%1/3
A // B
A= $args{"output_tokens"}B= $self->{"output_tokens"}
ABresult
1X1
011
000
222 });
223  
224 48 $out .= _event('message_stop', { type => 'message_stop' });
225 48 return $out;
226 }
227  
228  
229 10 ▶sub error_event {
Subroutine error_event: called CC=2 SCAR=7.0
Pod documented
230 10 my ($self, $status, $message, $type) = @_;
231 10 ▶ return '' if $self->{finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finished"} 0 10 10
232 10 $self->{finished} = 1;
233 10 $self->{errored} = 1;
234 10 return _event('error', Langertha::Skeid::Protocol::Anthropic->error_body($status, $message, $type));
235 }
236  
237  
238 49 ▶sub errored { $_[0]->{errored} }
Subroutine errored: called CC=1 SCAR=0.0
Pod documented
239  
240  
241 59 ▶sub usage {
Subroutine usage: called CC=1 SCAR=0.0
Pod documented
242 59 my ($self) = @_;
243 59 return ($self->{input_tokens}, $self->{output_tokens}, $self->{text_bytes});
244 }
245  
246  
247 50 1;
248  
249 __END__
250  
251 =pod
252  
253 =encoding UTF-8
254  
255 =head1 NAME
256  
257 Langertha::Skeid::Protocol::Anthropic::Stream - Rewrites an OpenAI SSE stream as Anthropic streaming events
258  
259 =head1 VERSION
260  
261 version 0.003
262  
263 =head1 DESCRIPTION
264  
265 Skeid makes one shape of upstream call and translates at the client edge (ADR 0001). For a
266 non-streaming response that is one function; for a stream it needs state, because Anthropic's
267 format is an event protocol rather than a sequence of deltas: a client is told a message began,
268 that a content block opened, then the text, then that both closed -- and the token counts arrive
269 in the closing events.
270  
271 An OpenAI stream says none of that. It sends deltas and stops. Everything else here is
272 synthesised at the right moment from what the OpenAI stream does say.
273  
274 my $stream = Langertha::Skeid::Protocol::Anthropic::Stream->new(model => 'claude-x');
275 $write->($stream->start);
276 $write->($stream->delta($openai_chunk)) for @chunks;
277 $write->($stream->finish);
278  
279 Every method returns bytes to write, possibly empty. C<start> and C<finish> are idempotent, so
280 a stream that fails mid-flight can still be closed correctly.
281  
282 =head2 new
283  
284 my $stream = Langertha::Skeid::Protocol::Anthropic::Stream->new(model => $requested_model);
285  
286 C<model> is the model named in C<message_start> -- the one the client asked for. C<message_id>
287 defaults to C<msg_> plus the current time in milliseconds.
288  
289 =head2 content_type
290  
291 The C<Content-Type> the client edge must send. Anthropic streams are SSE, same as OpenAI, but
292 the events inside are not interchangeable -- which is exactly why this class exists.
293  
294 =head2 start
295  
296 Opens the message. Content blocks are not opened here -- they open lazily on the first delta
297 of the kind that fills them, so a stream whose first content is a tool call does not emit an
298 empty text block before the tool_use block.
299  
300 =head2 delta
301  
302 my $bytes = $stream->delta($openai_chunk);
303  
304 Turns one decoded OpenAI chunk into whatever Anthropic events it implies: a
305 C<content_block_start> the first time a content block is seen (text or tool_use), one
306 C<content_block_delta> per delta of that block, and along the way the usage and finish
307 reason that the closing events need. The first chunk for a tool_calls index opens its
308 block; later arguments-only deltas for the same index extend it with partial_json.
309  
310 The translator carries enough state for parallel tool calls: each OpenAI tool_calls index is
311 mapped to its own Anthropic content block, allocated in order of first appearance, and the
312 list of still-open blocks is closed in order when C<finish> runs.
313  
314 A chunk carrying an OpenAI C<error> object instead of choices (how some servers report a
315 failure inside an open stream) ends the stream with L</error_event>.
316  
317 =head2 finish
318  
319 Closes every still-open content block and then the message. The token count goes on
320 C<message_delta>, because an Anthropic client reads usage from there, and so does the
321 C<stop_reason>: C<tool_use> whenever tool_use blocks were emitted and the upstream finished with
322 C<stop> or not at all, otherwise the mapping of the upstream C<finish_reason>.
323  
324 Idempotent, and it opens the message first if nothing ever did: a stream that produced no
325 text and no tool calls still has to be a well-formed Anthropic message, or the client waits
326 for an end that never comes. C<< stop_reason => ... >> and C<< output_tokens => ... >>
327 override what the stream recorded.
328  
329 =head2 error_event
330  
331 my $bytes = $stream->error_event(500, 'Upstream error: ...');
332 my $bytes = $stream->error_event(500, $message, $upstream_type);
333  
334 Ends the stream with an Anthropic C<event: error> frame, the way Anthropic reports a failure
335 after the stream has opened (the HTTP status is already 200 by then). The frame's data is
336 L<Langertha::Skeid::Protocol::Anthropic/error_body>, so its C<error.type> follows the same
337 status mapping as every other error on C</v1/messages>; an upstream error type Anthropic also
338 uses (an error chunk's C<rate_limit_error>, say) is kept.
339  
340 The stream is finished afterwards: C<delta> and C<finish> return nothing, so no
341 C<message_stop> follows and a client cannot mistake a failed stream for a complete one. Open
342 content blocks are left unclosed, as Anthropic leaves them. Returns nothing if the stream has
343 already finished.
344  
345 =head2 errored
346  
347 True once L</error_event> ended the stream, so the proxy records the request as failed even
348 though the HTTP status was 200.
349  
350 =head2 usage
351  
352 my ($input, $output, $content_bytes) = $stream->usage;
353  
354 What the stream carried, for the usage event. C<content_bytes> (UTF-8 bytes of the text this
355 translator wrote) becomes the event's C<content_bytes>, recorded beside the token counts on every
356 stream -- an observation, never an estimate of tokens.
357  
358 =head1 SEE ALSO
359  
360 L<Langertha::Skeid::Protocol::Anthropic>, L<Langertha::Skeid::Protocol::Ollama::Stream>
361  
362 =head1 SUPPORT
363  
364 =head2 Issues
365  
366 Please report bugs and feature requests on GitHub at
367 L<https://github.com/Getty/langertha-skeid/issues>.
368  
369 =head2 IRC
370  
371 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
372  
373 =head1 CONTRIBUTING
374  
375 Contributions are welcome! Please fork the repository and submit a pull request.
376  
377 =head1 AUTHOR
378  
379 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
380  
381 =head1 COPYRIGHT AND LICENSE
382  
383 This software is copyright (c) 2026 by Torsten Raudssus.
384  
385 This is free software; you can redistribute it and/or modify it under
386 the same terms as the Perl 5 programming language system itself.
387  
388 =cut
« blib/lib/Langertha/Skeid/KeyBroker/OpenBao.pm ↑ Summary blib/lib/Langertha/Skeid/UsageStore/DBI.pm »