NAME

Langertha::Stream::Chunk - Represents a single chunk from a streaming response

VERSION

version 0.500

SYNOPSIS

my $stream = $engine->simple_chat_stream_iterator('Tell me a story');

while (my $chunk = $stream->next) {
    print $chunk->content;

    if ($chunk->is_final) {
        say "\nModel: ", $chunk->model     if $chunk->has_model;
        say "Finish: ", $chunk->finish_reason if $chunk->has_finish_reason;
    }
}

DESCRIPTION

A single text chunk delivered during a streaming LLM response. Each chunk carries incremental content text and optional metadata. Chunks are collected into a Langertha::Stream iterator by "simple_chat_stream_iterator" in Langertha::Role::Chat.

content

The incremental text content delivered in this chunk. Required. For most chunks this is a word or partial word; the final chunk may be an empty string.

raw

The raw parsed API response data for this chunk as a HashRef. Use has_raw to check whether it was provided.

is_final

Boolean flag set to 1 on the last chunk of a stream. Defaults to 0.

model

The model identifier returned by the provider, if present. Use has_model to check availability.

finish_reason

The reason the stream ended: stop, length, tool_calls, etc. Provider-specific values are preserved as-is. undef on non-final chunks. Use has_finish_reason to check availability.

tool_calls

Optional ArrayRef of Langertha::ToolCall objects associated with this chunk. Populated when the engine emits tool-call information mid-stream (e.g. Anthropic's content_block_stop for a tool_use block, or the final OpenAI delta carrying assembled tool_calls). Most chunks have no tool calls — use has_tool_calls to check.

usage

Token usage counts as a HashRef, if provided by the engine on the final chunk. Keys vary by provider. Use has_usage to check availability.

SEE ALSO

SUPPORT

Issues

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

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

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

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.

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