Langertha/Engine/OpenRouter.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 86.2% 25 / 29 CC 2 SCAR 3.1
CC
2
Cov
90%
_build_api_key
2.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Langertha/Engine/DeepSeek.pm ↑ Summary Langertha/Engine/Replicate.pm »
1 package Langertha::Engine::OpenRouter;
2 # ABSTRACT: OpenRouter API
3 3 our $VERSION = '0.502';
4 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 extends 'Langertha::Engine::OpenAIBase';
8  
9 3 with 'Langertha::Role::Tools';
10  
11  
12 has '+url' => (
13 lazy => 1,
14 2 ▶ default => sub { 'https://openrouter.ai/api/v1' },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 3 );
16  
17 sub _build_api_key {
18 1 ▶ my ( $self ) = @_;
Subroutine _build_api_key: called CC=2 SCAR=8.1
19 return $ENV{LANGERTHA_OPENROUTER_API_KEY}
20 1 ▶ || croak "".(ref $self)." requires LANGERTHA_OPENROUTER_API_KEY or api_key set";
Condition33%1/3
$ENV{'LANGERTHA_OPENROUTER_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_OPENROUTER_API_KEY or api_key set')
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{'LANGERTHA_OPENROUTER_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_OPENROUTER_API_KEY or api_key set')
$ENV{'LANGERTHA_OPENROUTER_API_KEY'} croak('' . ref($self) . ' requires LANGERTHA_OPENROUTER_API_KEY or api_key set')
Truth table33%1/3
A || B
A= $ENV{'LANGERTHA_OPENROUTER_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_OPENROUTER_API_KEY or api_key set')
ABresult
1X1
011
000
21 }
22  
23 1 ▶sub default_model { croak "".(ref $_[0])." requires model to be set" }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
24  
25 1 ▶sub _build_supported_operations {[qw(
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
26 createChatCompletion
27 )]}
28  
29 3 __PACKAGE__->meta->make_immutable;
30  
31  
32 3 1;
33  
34 __END__
35  
36 =pod
37  
38 =encoding UTF-8
39  
40 =head1 NAME
41  
42 Langertha::Engine::OpenRouter - OpenRouter API
43  
44 =head1 VERSION
45  
46 version 0.502
47  
48 =head1 SYNOPSIS
49  
50 use Langertha::Engine::OpenRouter;
51  
52 my $router = Langertha::Engine::OpenRouter->new(
53 api_key => $ENV{OPENROUTER_API_KEY},
54 model => 'anthropic/claude-sonnet-4-6',
55 );
56  
57 print $router->simple_chat('Hello from Perl!');
58  
59 # Access many providers through one API
60 my $deepseek = Langertha::Engine::OpenRouter->new(
61 api_key => $ENV{OPENROUTER_API_KEY},
62 model => 'deepseek/deepseek-r1',
63 );
64  
65 =head1 DESCRIPTION
66  
67 Provides access to OpenRouter, a unified API gateway for 300+ models from
68 many providers (OpenAI, Anthropic, Google, Meta, Mistral, and more).
69 Composes L<Langertha::Role::OpenAICompatible> with OpenRouter's endpoint
70 (C<https://openrouter.ai/api/v1>).
71  
72 Model names use C<provider/model> format (e.g., C<anthropic/claude-sonnet-4-6>,
73 C<openai/gpt-4o>, C<google/gemini-2.5-flash>). No default model is set;
74 C<model> must be specified explicitly.
75  
76 Supports chat, streaming, and MCP tool calling. Embeddings and transcription
77 are not supported.
78  
79 Get your API key at L<https://openrouter.ai/settings/keys> and set
80 C<LANGERTHA_OPENROUTER_API_KEY> in your environment.
81  
82 B<THIS API IS WORK IN PROGRESS>
83  
84 =head1 SEE ALSO
85  
86 =over
87  
88 =item * L<https://status.openrouter.ai/> - OpenRouter service status
89  
90 =item * L<https://openrouter.ai/docs> - OpenRouter documentation
91  
92 =item * L<https://openrouter.ai/models> - Browse available models
93  
94 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role
95  
96 =back
97  
98 =head1 SUPPORT
99  
100 =head2 Issues
101  
102 Please report bugs and feature requests on GitHub at
103 L<https://github.com/Getty/langertha/issues>.
104  
105 =head2 IRC
106  
107 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
108  
109 =head1 CONTRIBUTING
110  
111 Contributions are welcome! Please fork the repository and submit a pull request.
112  
113 =head1 AUTHOR
114  
115 Torsten Raudssus <getty@cpan.org>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
120  
121 This is free software; you can redistribute it and/or modify it under
122 the same terms as the Perl 5 programming language system itself.
123  
124 =cut
« Langertha/Engine/DeepSeek.pm ↑ Summary Langertha/Engine/Replicate.pm »