NAME

Langertha::Knarr::Router - Model name to Langertha engine routing with caching

VERSION

version 0.004

SYNOPSIS

use Langertha::Knarr::Router;

my $router = Langertha::Knarr::Router->new(config => $config);

my ($engine, $model) = $router->resolve('gpt-4o');
my $result = $engine->simple_chat(@messages);

my $models = $router->list_models;

DESCRIPTION

Resolves a model name to a Langertha engine instance and canonical model identifier. Engine instances are cached and reused across requests to avoid repeated construction overhead.

When auto_discover is enabled in the config, the router queries each configured engine for its full model list on first use, making all discovered models available as routing targets.

config

The Langertha::Knarr::Config object. Required.

resolve

my ($engine, $model) = $router->resolve($model_name, %opts);
my ($engine, $model) = $router->resolve($model_name, skip_default => 1);

Resolves $model_name to a Langertha engine instance and the canonical model string to use with that engine. The resolution order is:

1. Explicit model config in "models" in Langertha::Knarr::Config
2. Auto-discovered models (if auto_discover is enabled)
3. The default engine from "default_engine" in Langertha::Knarr::Config (skipped when skip_default => 1 is passed)

Croaks if the model cannot be resolved. Pass skip_default => 1 to allow the caller to try passthrough before falling back to the default engine.

list_models

my $models = $router->list_models;

Returns an ArrayRef of model hashrefs, each with keys id, engine, model, and source (either configured or discovered). Triggers auto-discovery if not already done. Used to build the model list responses for GET /v1/models and GET /api/tags.

SEE ALSO

SUPPORT

Issues

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

CONTRIBUTING

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

AUTHOR

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

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.