NAME

Langertha::ImageGen - Image generation abstraction wrapping an engine with optional overrides

VERSION

version 0.503

SYNOPSIS

use Langertha::Engine::OpenAI;
use Langertha::ImageGen;

my $engine = Langertha::Engine::OpenAI->new(
    api_key => $ENV{OPENAI_API_KEY},
);

my $image_gen = Langertha::ImageGen->new(
    engine  => $engine,
    model   => 'gpt-image-2',
    size    => '1024x1024',
    quality => 'high',
    plugins => ['Langfuse'],
);

my $result = $image_gen->simple_image('A cat riding a bicycle through Paris');

DESCRIPTION

Langertha::ImageGen wraps any engine that consumes Langertha::Role::ImageGeneration and adds optional overrides for model, size, and quality, plus plugin lifecycle hooks via Langertha::Role::PluginHost.

Use this class when you need multiple image generation configurations from the same engine instance, or when you want plugin observability (e.g. Langertha::Plugin::Langfuse) without modifying the engine.

engine

The LLM engine to delegate image generation requests to. Must consume Langertha::Role::ImageGeneration.

model

Optional model name override. When set, overrides the engine's image_model via %extra pass-through.

size

Optional image size (e.g. '1024x1024', '1536x1024').

quality

Optional quality setting (e.g. 'low', 'medium', 'high' for GPT image models).

simple_image

my $result = $image_gen->simple_image('A cat in space');

Returns the image generation result for $prompt. If model, size, or quality overrides are set, uses them via %extra; otherwise delegates to the engine's simple_image. Plugin hooks plugin_before_image_gen and plugin_after_image_gen are fired.

simple_image_f

my $result = await $image_gen->simple_image_f('A cat in space');

Async variant of "simple_image": the same result, overrides and plugin hooks, with the hooks awaited and the request sent through the engine's async backend (see "simple_image_f" in Langertha::Role::ImageGeneration).

simple_image_result

my $result = $image_gen->simple_image_result('A cat in space');
my $images = $result->value;
say $result->usage->output_tokens if $result->has_usage;

Like "simple_image", with the same overrides and plugin hooks, but returns the Langertha::CallResult of "simple_image_result" in Langertha::Role::ImageGeneration: value is the image result after the after-hooks, and usage, rate_limit, model and total_seconds are the call's. plugin_after_image_gen gets that CallResult as an extra third argument (see Langertha::Plugin). When a hook returns a different value, the result is a new CallResult with that value and the other attributes copied.

simple_image_result_f

my $result = await $image_gen->simple_image_result_f('A cat in space');

Async variant of "simple_image_result": the same result, overrides and hooks, sent through the engine's async backend like "simple_image_f".

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.