hanzo-server-core 0.6.1

Hanzo Engine - fast, flexible LLM inference engine written in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
//! Zen SKU -> HF repo -> arch registry.
//!
//! When a client sends `model: "zen5-pro"` over `/v1/messages` or
//! `/v1/chat/completions`, the engine looks up that SKU here to decide which
//! Hugging Face repo to fetch and which backend arch (deepseek-v4-flash,
//! qwen3-moe, qwen3-vl, ...) to load.
//!
//! Three things live here:
//!   1. The canonical Zen SKU set served by zen-gateway and listed in
//!      `pricing/src/models.mjs::zenCatalog`.
//!   2. The HF source repo (under `zenlm/`) for each SKU.
//!   3. The arch kind, which is either `Supported(NormalLoaderType)` or
//!      `Unsupported(name)` for archs not yet ported. The server uses the
//!      latter to return a clean 501 instead of a 500 deep in the loader.
//!
//! Adding a new SKU is a one-line change in `zen_sku_table()`. Porting a new
//! arch (qwen3-vl, qwen3-asr, ...) is out of scope for this registry; once the
//! arch lands in `hanzo-engine`, flip the `Unsupported` to `Supported`.

use std::collections::HashMap;
use std::sync::OnceLock;

/// Backend modality. Matches the gateway/pricing modality taxonomy.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Modality {
    Text,
    Vision,
    Audio,
    Embedding,
}

/// Which arch loads this SKU.
///
/// `Supported` carries the engine's NormalLoaderType name (the same string
/// `NormalLoaderType::from_str` accepts). `Unsupported` carries a free-form
/// placeholder so handlers can produce a 501 with a useful message and a
/// pointer to the planned arch name.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ArchKind {
    Supported(&'static str),
    Unsupported(&'static str),
}

impl ArchKind {
    pub fn name(&self) -> &'static str {
        match self {
            ArchKind::Supported(n) | ArchKind::Unsupported(n) => n,
        }
    }

    pub fn is_supported(&self) -> bool {
        matches!(self, ArchKind::Supported(_))
    }
}

/// A single Zen SKU entry.
#[derive(Debug, Clone)]
pub struct ZenSku {
    /// User-facing SKU name (e.g. `zen5-pro`). What clients put in `model`.
    pub sku: &'static str,
    /// Hugging Face repo id (e.g. `zenlm/zen-5-pro-gguf`).
    pub hf_repo: &'static str,
    /// Backend arch.
    pub arch: ArchKind,
    /// Quant variant when applicable (`IQ2_XXS`, `Q4_K_M`, ...), else `None`.
    pub quant: Option<&'static str>,
    pub modality: Modality,
}

/// Canonical Zen SKU table.
///
/// Source of truth is the intersection of zen-gateway `config.yaml::model_list`
/// and pricing `models.mjs::zenCatalog`. Add/edit rows here, then run
/// `cargo check -p hanzo-server-core`.
fn zen_sku_table() -> &'static [ZenSku] {
    &[
        // ---- Zen5 ladder (canonical) ---------------------------------------
        // zen5-nano-*: Zen VL dense edge tier. Multimodal but qwen3-vl arch is
        // not yet ported; mark Unsupported until the encoder lands.
        ZenSku {
            sku: "zen5-nano-0.8B",
            hf_repo: "zenlm/zen-5-nano-0.8b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen5-nano-2B",
            hf_repo: "zenlm/zen-5-nano-2b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen5-nano-4B",
            hf_repo: "zenlm/zen-5-nano-4b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen5-nano-9B",
            hf_repo: "zenlm/zen-5-nano-9b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        // Text-only Zen5 ladder. qwen3 / qwen3moe are in tree.
        ZenSku {
            sku: "zen5-flash",
            hf_repo: "zenlm/zen-5-flash",
            arch: ArchKind::Supported("qwen3"),
            quant: None,
            modality: Modality::Text,
        },
        ZenSku {
            sku: "zen5-mini",
            hf_repo: "zenlm/zen-5-mini",
            arch: ArchKind::Supported("qwen3moe"),
            quant: None,
            modality: Modality::Text,
        },
        ZenSku {
            sku: "zen5",
            hf_repo: "zenlm/zen-5",
            arch: ArchKind::Supported("qwen3moe"),
            quant: None,
            modality: Modality::Text,
        },
        ZenSku {
            sku: "zen5-coder",
            hf_repo: "zenlm/zen-5-coder",
            arch: ArchKind::Supported("qwen3moe"),
            quant: None,
            modality: Modality::Text,
        },
        // Zen5 Pro/Max/Ultra ride on DeepSeek V4 (zen5 branch arch, "Zen5"
        // internally). DS4 is not on main; flip to Supported once
        // hanzo-engine/src/models/zen5.rs lands here.
        ZenSku {
            sku: "zen5-pro",
            hf_repo: "zenlm/zen-5-pro-gguf",
            arch: ArchKind::Unsupported("deepseek-v4-flash"),
            quant: Some("IQ2_XXS"),
            modality: Modality::Text,
        },
        ZenSku {
            sku: "zen5-max",
            hf_repo: "zenlm/zen-5-max-gguf",
            arch: ArchKind::Unsupported("deepseek-v4-pro"),
            quant: Some("Q4_K_M"),
            modality: Modality::Text,
        },
        // Zen5 embeddings. qwen3 backbone is in tree but the embedding head
        // is served by `hanzo-engine::pipeline::embedding`, which already
        // wraps qwen3-style backbones.
        ZenSku {
            sku: "zen5-embedding-0.6B",
            hf_repo: "zenlm/zen-5-embedding-0.6b",
            arch: ArchKind::Supported("qwen3"),
            quant: None,
            modality: Modality::Embedding,
        },
        ZenSku {
            sku: "zen5-embedding-4B",
            hf_repo: "zenlm/zen-5-embedding-4b",
            arch: ArchKind::Supported("qwen3"),
            quant: None,
            modality: Modality::Embedding,
        },
        ZenSku {
            sku: "zen5-embedding-8B",
            hf_repo: "zenlm/zen-5-embedding-8b",
            arch: ArchKind::Supported("qwen3"),
            quant: None,
            modality: Modality::Embedding,
        },
        // Zen4 generation (zen4, zen4-pro, zen4-max, zen4.1, zen4-mini,
        // zen4-ultra, zen4-thinking, zen4-coder, zen4-coder-flash,
        // zen4-coder-pro) sunset 2026-05-30 with the zenlm/zen4* HF mirrors.
        // Routing still works via the gateway's Fireworks aliases for any
        // legacy callers, but the engine no longer claims to be able to load
        // them directly. Use the zen5 ladder instead.

        // ---- Zen3 family (multimodal + specialty) --------------------------
        ZenSku {
            sku: "zen3-omni",
            hf_repo: "zenlm/zen-omni",
            arch: ArchKind::Unsupported("qwen3-omni"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen3-vl",
            hf_repo: "zenlm/zen-vl",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen3-vl-2B",
            hf_repo: "zenlm/zen-vl-2b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen3-vl-8B",
            hf_repo: "zenlm/zen-vl-8b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen3-vl-32B",
            hf_repo: "zenlm/zen-vl-32b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        ZenSku {
            sku: "zen3-vl-235B-A22B",
            hf_repo: "zenlm/zen-vl-235b-a22b",
            arch: ArchKind::Unsupported("qwen3-vl"),
            quant: None,
            modality: Modality::Vision,
        },
        // zen3-vl-reranker-{2B,8B}, zen3-vl-embedding-{2B,8B}, and
        // zen3-web-{8B,14B,32B} were virtual SKUs with no HF weights — removed
        // 2026-05-30. The canonical zen3-vl-* size variants above remain.
        ZenSku {
            sku: "zen3-nano",
            hf_repo: "zenlm/zen-nano-0.6b",
            arch: ArchKind::Supported("llama"),
            quant: None,
            modality: Modality::Text,
        },
        ZenSku {
            sku: "zen3-guard",
            hf_repo: "zenlm/zen-guard",
            arch: ArchKind::Supported("mixtral"),
            quant: None,
            modality: Modality::Text,
        },
        // Zen3 ASR / TTS — encoders not ported.
        ZenSku {
            sku: "zen3-asr",
            hf_repo: "zenlm/zen-asr-1.7b",
            arch: ArchKind::Unsupported("qwen3-asr"),
            quant: None,
            modality: Modality::Audio,
        },
        ZenSku {
            sku: "zen3-asr-0.6B",
            hf_repo: "zenlm/zen-asr-0.6b",
            arch: ArchKind::Unsupported("qwen3-asr"),
            quant: None,
            modality: Modality::Audio,
        },
        ZenSku {
            sku: "zen3-asr-aligner",
            hf_repo: "zenlm/zen-asr-aligner-0.6b",
            arch: ArchKind::Unsupported("qwen3-asr"),
            quant: None,
            modality: Modality::Audio,
        },
        ZenSku {
            sku: "zen3-tts",
            hf_repo: "zenlm/zen-tts-1.7b",
            arch: ArchKind::Unsupported("qwen3-tts"),
            quant: None,
            modality: Modality::Audio,
        },
        ZenSku {
            sku: "zen3-tts-0.6B",
            hf_repo: "zenlm/zen-tts-0.6b",
            arch: ArchKind::Unsupported("qwen3-tts"),
            quant: None,
            modality: Modality::Audio,
        },
        ZenSku {
            sku: "zen3-tts-voice-design",
            hf_repo: "zenlm/zen-tts-voicedesign-1.7b",
            arch: ArchKind::Unsupported("qwen3-tts"),
            quant: None,
            modality: Modality::Audio,
        },
        ZenSku {
            sku: "zen3-tts-custom-voice",
            hf_repo: "zenlm/zen-tts-customvoice-1.7b",
            arch: ArchKind::Unsupported("qwen3-tts"),
            quant: None,
            modality: Modality::Audio,
        },
        // Zen3 embeddings (text-only, in-tree). zen3-embedding-medium /
        // zen3-embedding-small ghost aliases were sunset 2026-05-30; use the
        // zen5-embedding-{0.6B,4B,8B} ladder for new integrations.
        ZenSku {
            sku: "zen3-embedding",
            hf_repo: "zenlm/zen-embedding",
            arch: ArchKind::Supported("qwen3"),
            quant: None,
            modality: Modality::Embedding,
        },
    ]
}

/// SKU -> entry index. Built on first lookup.
fn index() -> &'static HashMap<&'static str, usize> {
    static IDX: OnceLock<HashMap<&'static str, usize>> = OnceLock::new();
    IDX.get_or_init(|| {
        zen_sku_table()
            .iter()
            .enumerate()
            .map(|(i, e)| (e.sku, i))
            .collect()
    })
}

/// Look up an SKU. Case-sensitive — the canonical case matches `zenCatalog`.
pub fn lookup(sku: &str) -> Option<&'static ZenSku> {
    index().get(sku).map(|&i| &zen_sku_table()[i])
}

/// Iterate every registered SKU.
pub fn all() -> &'static [ZenSku] {
    zen_sku_table()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn skus_are_unique() {
        let table = zen_sku_table();
        let mut seen = std::collections::HashSet::new();
        for e in table {
            assert!(seen.insert(e.sku), "duplicate SKU `{}`", e.sku);
        }
    }

    #[test]
    fn known_skus_resolve() {
        for sku in [
            "zen5",
            "zen5-pro",
            "zen5-max",
            "zen5-flash",
            "zen5-coder",
            "zen5-embedding-8B",
            "zen3-vl",
            "zen3-asr",
            "zen3-nano",
        ] {
            assert!(lookup(sku).is_some(), "missing SKU `{sku}`");
        }
    }

    #[test]
    fn sunset_skus_are_absent() {
        // Zen4 generation + virtual zen3 aliases were removed 2026-05-30.
        for sku in [
            "zen4",
            "zen4-pro",
            "zen4-max",
            "zen4.1",
            "zen4-mini",
            "zen4-ultra",
            "zen4-thinking",
            "zen4-coder",
            "zen4-coder-flash",
            "zen4-coder-pro",
            "zen5-ultra",
            "zen3-vl-reranker-2B",
            "zen3-vl-reranker-8B",
            "zen3-vl-embedding-2B",
            "zen3-vl-embedding-8B",
            "zen3-web-8B",
            "zen3-web-14B",
            "zen3-web-32B",
            "zen3-embedding-small",
            "zen3-embedding-medium",
        ] {
            assert!(
                lookup(sku).is_none(),
                "sunset SKU `{sku}` still in registry"
            );
        }
    }

    #[test]
    fn unsupported_arches_are_explicit() {
        let pro = lookup("zen5-pro").unwrap();
        assert!(!pro.arch.is_supported());
        assert_eq!(pro.arch.name(), "deepseek-v4-flash");
        let vl = lookup("zen3-vl").unwrap();
        assert!(!vl.arch.is_supported());
        assert_eq!(vl.arch.name(), "qwen3-vl");
    }

    #[test]
    fn supported_arch_names_match_normal_loader() {
        for e in all().iter().filter(|e| e.arch.is_supported()) {
            match e.arch.name() {
                "qwen3" | "qwen3moe" | "deepseekv3" | "glm4moe" | "llama" | "mixtral"
                | "gpt_oss" => {}
                other => panic!(
                    "SKU `{}` uses arch `{}` not in NormalLoaderType",
                    e.sku, other
                ),
            }
        }
    }
}