NAME

Langertha::Engine::Gemini - Google Gemini API

VERSION

version 0.302

SYNOPSIS

use Langertha::Engine::Gemini;

my $gemini = Langertha::Engine::Gemini->new(
    api_key      => $ENV{GEMINI_API_KEY},
    model        => 'gemini-2.5-flash',
    response_size => 4096,
    temperature  => 0.7,
);

# Simple chat
my $response = $gemini->simple_chat('Explain quantum computing in simple terms');
print $response;

# Streaming
$gemini->simple_chat_stream(sub {
    my ($chunk) = @_;
    print $chunk->content;
}, 'Write a poem about Perl');

# Async with Future::AsyncAwait
use Future::AsyncAwait;

async sub ask_gemini {
    my $response = await $gemini->simple_chat_f(
        'What are the benefits of functional programming?'
    );
    say $response;
}

DESCRIPTION

Provides access to Google's Gemini models via the Generative Language API. Gemini models support multimodal input (text, code, images) and long context windows.

Available models include gemini-2.5-flash (fast with thinking, default), gemini-2.5-pro (most capable), and gemini-2.0-flash (previous generation). The default API endpoint is https://generativelanguage.googleapis.com.

THIS API IS WORK IN PROGRESS

api_key

The Google Generative Language API key. If not provided, reads from LANGERTHA_GEMINI_API_KEY environment variable. Get your key at https://aistudio.google.com/app/apikey. Required.

list_models

my $model_ids = $engine->list_models;
my $models    = $engine->list_models(full => 1);
my $models    = $engine->list_models(force_refresh => 1);

Fetches available models from the Gemini API using token pagination. Returns an ArrayRef of model ID strings (with the models/ prefix stripped) by default, or full model objects when full = 1> is passed. Results are cached for models_cache_ttl seconds (default: 3600).

SEE ALSO

SUPPORT

Issues

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

CONTRIBUTING

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

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudss.us/

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

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