blib/lib/Langertha/Engine/Hetzner.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 78.5% 33 / 42 CC 2 SCAR 6.9
CC
2
Cov
83%
_build_api_key
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Langertha/Role/Runtime/MetricsPoll.pm ↑ Summary blib/lib/Langertha/Spec/LMStudio.pm »
1 package Langertha::Engine::Hetzner;
2 # ABSTRACT: Hetzner Inference API (OpenAI-compatible)
3 8 our $VERSION = '0.503';
4 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 extends 'Langertha::Engine::OpenAIBase';
8  
9 8 with map { 'Langertha::Role::'.$_ } qw(
10 StaticModels
11 Tools
12 );
13  
14  
15  
16 23 ▶sub _build_supported_operations {[qw(
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
17 createChatCompletion
18 )]}
19  
20 has '+url' => (
21 lazy => 1,
22 12 ▶ default => sub { 'https://inference.hetzner.com/api/v1' },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 8 );
24  
25 0 ▶sub _build_api_key {
Subroutine _build_api_key: not called CC=2 SCAR=17.9
26 0 my ( $self ) = @_;
27 return $ENV{LANGERTHA_HETZNER_API_KEY}
28 0 ▶ || croak "".(ref $self)." requires LANGERTHA_HETZNER_API_KEY or api_key set";
Condition0%0/3
$ENV{'LANGERTHA_HETZNER_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_HETZNER_API_KEY or api_key set')
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'LANGERTHA_HETZNER_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_HETZNER_API_KEY or api_key set')
$ENV{'LANGERTHA_HETZNER_API_KEY'} croak('' . ref($self) . ' requires LANGERTHA_HETZNER_API_KEY or api_key set')
Truth table0%0/3
A || B
A= $ENV{'LANGERTHA_HETZNER_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_HETZNER_API_KEY or api_key set')
ABresult
1X1
011
000
29 }
30  
31 23 ▶sub default_model { 'Qwen/Qwen3.6-35B-A3B-FP8' }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
32  
33 # image_input (k266, ADR 0019 k266 Update): both catalog models take image input
34 # (see MODELS), so the engine keeps the flag Role::ImageInput (via OpenAIBase)
35 # brings and needs no model rows. A text-only catalog addition gets a layer-3
36 # clear row here.
37  
38 84 ▶sub default_response_size { 4096 }
Subroutine default_response_size: called CC=1 SCAR=0.0
Pod undocumented
39  
40 # DOC-SOURCED, NOT LIVE-CONFIRMED (Hetzner blog "inference-experiment", reduced
41 # scope, 2026-08-17 + docs catalog, checked 2026-09-17): the Inference
42 # experiment was narrowed to the small Qwen models — DeepSeek-V4-Flash-0731,
43 # GLM-5.2-NVFP4 and Kimi-K2.7-Code were retired. This list reflects the
44 # published docs, not a live /v1/models read. The drift check in
45 # t/88_live_hetzner.t (karr k40) should confirm against the live endpoint
46 # before this catalog is considered frozen.
47 1 ▶sub _build_static_models {[
Subroutine _build_static_models: called CC=1 SCAR=0.0
48 1 { id => 'Qwen/Qwen3.6-35B-A3B-FP8' },
49 { id => 'Qwen3.8-27B' },
50 ]}
51  
52 # Hetzner Inference documents neither tool calling nor structured output on its
53 # OpenAI-compatible endpoint, and the platform is explicitly experimental —
54 # "you should not use the platform for production environments"
55 # (docs.hetzner.com/general/company-and-policy/experiments/inference/, verified
56 # 2026-09-01). Only /v1/models, /v1/completions and /v1/chat/completions exist.
57 # The wire shape is OpenAI-compatible, so the role inventory grants the tool and
58 # response_format flags — but nothing confirms the gateway honors them, so clear
59 # them rather than advertise capabilities that may silently no-op. Re-add via
60 # this around once a live test confirms them.
61 120 ▶around engine_capabilities => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
62 120 my ( $orig, $self, @rest ) = @_;
63 120 my $caps = $self->$orig(@rest);
64 120 delete @{$caps}{ qw(
65 tools_native
66 tool_choice_auto tool_choice_any tool_choice_none tool_choice_named
67 response_format_json_object response_format_json_schema
68 parallel_tool_use
69 ) };
70 120 return $caps;
71 8 };
72  
73 8 __PACKAGE__->meta->make_immutable;
74  
75  
76  
77 8 1;
78  
79 __END__
80  
81 =pod
82  
83 =encoding UTF-8
84  
85 =head1 NAME
86  
87 Langertha::Engine::Hetzner - Hetzner Inference API (OpenAI-compatible)
88  
89 =head1 VERSION
90  
91 version 0.503
92  
93 =head1 SYNOPSIS
94  
95 use Langertha::Engine::Hetzner;
96  
97 my $hetzner = Langertha::Engine::Hetzner->new(
98 api_key => $ENV{LANGERTHA_HETZNER_API_KEY},
99 );
100  
101 print $hetzner->simple_chat('Hello from Perl!');
102  
103 # Streaming
104 $hetzner->simple_chat_stream(sub {
105 print shift->content;
106 }, 'Write a poem');
107  
108 # Vision (Qwen/Qwen3.6-35B-A3B-FP8 accepts image_url content parts)
109 use Langertha::Content::Image;
110 my $img = Langertha::Content::Image->from_url('https://example.com/cat.jpg');
111 my $resp = await $hetzner->simple_chat_f({
112 role => 'user',
113 content => [ 'What is in this image?', $img ],
114 });
115  
116 # Tool calling
117 my $response = await $hetzner->chat_with_tools_f('Search for Perl modules');
118  
119 =head1 DESCRIPTION
120  
121 Provides access to L<Hetzner Cloud|https://www.hetzner.com/>'s
122 L<Inference API|https://inference.hetzner.com/api/v1> via their
123 OpenAI-compatible endpoint at C<https://inference.hetzner.com/api/v1>.
124  
125 Hetzner's Inference API is currently experimental and free of charge; rate
126 limits are 10M input / 200K output tokens per 60 seconds per API key (HTTP 429
127 when exceeded). Bearer-token authentication via
128 C<LANGERTHA_HETZNER_API_KEY>.
129  
130 Supports chat, streaming, tool calling, structured output (OpenAI-compatible
131 C<response_format>), and image inputs (C<image_url> content parts) on the
132 vision-capable models. Embeddings and transcription are not available on this
133 endpoint.
134  
135 =head1 DEFAULT MODEL
136  
137 C<Qwen/Qwen3.6-35B-A3B-FP8> — one of the two currently-listed Hetzner models,
138 an MoE (35B total / 3B activated), Apache 2.0, text + image input, 262K context
139 window. Picked because it is distinct from the existing
140 L<Langertha::Engine::Moonshot> default (Kimi K3); the catalog's only other entry
141 (C<Qwen3.8-27B>, a dense 27B model) is likewise text + image, so the choice is a
142 capacity/architecture preference rather than a modality one.
143  
144 =head1 MODELS
145  
146 The two models currently listed at C</api/v1/models> (Hetzner narrowed the
147 Inference experiment to the small Qwen models in Aug 2026, retiring the earlier
148 DeepSeek/GLM/Kimi checkpoints):
149  
150 =over 4
151  
152 =item * C<Qwen/Qwen3.6-35B-A3B-FP8> — C<default>. Apache 2.0. MoE 35B/3B.
153 262K context. Text + image input.
154  
155 =item * C<Qwen3.8-27B> — dense 27B. 262K context. Text + image input.
156  
157 =back
158  
159 B<Tool support caveat:> the Hetzner Inference docs do not confirm server-side
160 tool calling or structured output on the OpenAI-compatible endpoint, and the
161 platform is explicitly experimental. The engine composes L<Langertha::Role::Tools>
162 (so C<chat_with_tools_f> exists) and L<Langertha::Role::ResponseFormat>, but
163 C<engine_capabilities> B<clears> C<tools_native>, every C<tool_choice_*>,
164 C<parallel_tool_use> and both C<response_format_*> flags rather than advertise
165 capabilities that may silently no-op. Tools you pass still go out in the
166 C<tools> array, but C<tool_choice> and C<parallel_tool_calls> are no longer
167 sent: C<auto> is dropped silently, a forced choice with a warning, and
168 C<none> leaves the tools out instead (see L<Langertha::Role::Chat/chat_f>).
169 If a live test confirms the gateway honors them for the model you use,
170 re-add them in the engine's C<around engine_capabilities>.
171  
172 B<No embeddings or transcription:> the Hetzner Inference endpoint exposes chat
173 completions + image processing only. L</embedding> and L</transcription> are
174 not composed on this engine.
175  
176 Get your API key at L<https://inference.hetzner.com/> and set
177 C<LANGERTHA_HETZNER_API_KEY> in your environment.
178  
179 =head1 REFRESHING THE MODEL CATALOG
180  
181 To add or remove a model: edit C<_build_static_models> below, update the
182 L</MODELS> POD block to match, add a Changes entry, and run the offline
183 tests (C<t/48_hetzner.t>, C<t/00_load.t>). The live drift check in
184 C<t/88_live_hetzner.t> (karr #40) compares the hardcoded catalog against
185 L<https://inference.hetzner.com/api/v1/models> and warns on missing models.
186  
187 =head1 CAPABILITIES
188  
189 Advertised flags (derived from composed roles via L<Langertha::Role::Capabilities>):
190  
191 =over 4
192  
193 =item * C<chat> — L<Langertha::Role::Chat>
194  
195 =item * C<streaming> — L<Langertha::Role::Streaming>
196  
197 =item * C<temperature> — L<Langertha::Role::Temperature>
198  
199 =item * C<response_size>, C<system_prompt>, C<context_size>, C<seed>
200 — generation-parameter knobs the engine will honour
201  
202 =back
203  
204 C<tools_native>, C<tool_choice_*>, C<parallel_tool_use> and
205 C<response_format_*> are B<not> advertised even though L<Langertha::Role::Tools>
206 and L<Langertha::Role::ResponseFormat> are composed — the engine clears them in
207 its C<around engine_capabilities> (see the tool-support caveat above). Tools
208 are still sent; C<tool_choice> and C<parallel_tool_calls> are not. If a live
209 test confirms them, re-add them there.
210  
211 Vision input is supported on both currently-listed models
212 (Qwen/Qwen3.6-35B-A3B-FP8 and Qwen3.8-27B) via C<image_url> content parts; this
213 is handled by L<Langertha::Content::Image> and L<Langertha::Role::Chat>'s
214 normalization — there is no engine-level C<vision> flag.
215  
216 =head1 SEE ALSO
217  
218 =over
219  
220 =item * L<Langertha::Engine::Moonshot> - Another OpenAI-compatible cloud engine with multimodal support
221  
222 =item * L<Langertha::Engine::XAI> - Another OpenAI-compatible cloud engine with vision + tool calling
223  
224 =item * L<https://inference.hetzner.com/> - Hetzner Inference API
225  
226 =item * L<Langertha::Engine::OpenAIBase> - Base class for OpenAI-compatible engines
227  
228 =item * L<Langertha::Role::Tools> - MCP tool calling interface
229  
230 =back
231  
232 =head1 SUPPORT
233  
234 =head2 Issues
235  
236 Please report bugs and feature requests on GitHub at
237 L<https://github.com/Getty/langertha/issues>.
238  
239 =head2 IRC
240  
241 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
242  
243 =head1 CONTRIBUTING
244  
245 Contributions are welcome! Please fork the repository and submit a pull request.
246  
247 =head1 AUTHOR
248  
249 Torsten Raudssus <getty@cpan.org>
250  
251 =head1 COPYRIGHT AND LICENSE
252  
253 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
254  
255 This is free software; you can redistribute it and/or modify it under
256 the same terms as the Perl 5 programming language system itself.
257  
258 =cut
« blib/lib/Langertha/Role/Runtime/MetricsPoll.pm ↑ Summary blib/lib/Langertha/Spec/LMStudio.pm »