litellm-rs 0.8.2

A high-performance AI Gateway written in Rust, providing OpenAI-compatible APIs with intelligent routing, load balancing, and enterprise features
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//! Legacy adapter availability matrix.
//!
//! This matrix records selector-based adapters from the legacy provider/config
//! paths. Canonical runtime entry points do not consult it: they derive support
//! from the selected deployment's `ProviderCapability`.

use super::{canonical_catalog_name, entry_for_name, get_definition};

/// Compatibility entry points covered by the legacy adapter matrix.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LegacyAdapterSurface {
    HttpChat,
    HttpChatStream,
    HttpEmbeddings,
    HttpRerank,
    HttpImageGeneration,
    SdkChat,
    SdkChatStream,
    SdkEmbeddings,
    CompletionChat,
    CompletionChatStream,
}

/// Availability state for one provider/legacy-adapter pair.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LegacyAdapterAvailability {
    Supported,
    Passthrough,
    FeatureGated(&'static str),
    Unsupported,
}

impl LegacyAdapterAvailability {
    /// True when the legacy adapter is available in the current binary.
    pub fn is_available_in_current_build(self) -> bool {
        match self {
            Self::Supported | Self::Passthrough => true,
            Self::FeatureGated("providers-extra") => cfg!(feature = "providers-extra"),
            Self::FeatureGated("providers-extended") => cfg!(feature = "providers-extended"),
            Self::FeatureGated(_) | Self::Unsupported => false,
        }
    }

    pub fn markdown_cell(self) -> &'static str {
        match self {
            Self::Supported => "yes",
            Self::Passthrough => "passthrough",
            Self::FeatureGated(feature) => feature,
            Self::Unsupported => "-",
        }
    }
}

/// One documented legacy adapter row.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ProviderLegacyAdapterSupport {
    pub selector: &'static str,
    pub http_chat: LegacyAdapterAvailability,
    pub http_chat_stream: LegacyAdapterAvailability,
    pub http_embeddings: LegacyAdapterAvailability,
    pub http_rerank: LegacyAdapterAvailability,
    pub http_image_generation: LegacyAdapterAvailability,
    pub sdk_chat: LegacyAdapterAvailability,
    pub sdk_chat_stream: LegacyAdapterAvailability,
    pub sdk_embeddings: LegacyAdapterAvailability,
    pub completion_chat: LegacyAdapterAvailability,
    pub completion_chat_stream: LegacyAdapterAvailability,
    pub notes: &'static str,
}

impl ProviderLegacyAdapterSupport {
    pub fn availability_for(self, surface: LegacyAdapterSurface) -> LegacyAdapterAvailability {
        match surface {
            LegacyAdapterSurface::HttpChat => self.http_chat,
            LegacyAdapterSurface::HttpChatStream => self.http_chat_stream,
            LegacyAdapterSurface::HttpEmbeddings => self.http_embeddings,
            LegacyAdapterSurface::HttpRerank => self.http_rerank,
            LegacyAdapterSurface::HttpImageGeneration => self.http_image_generation,
            LegacyAdapterSurface::SdkChat => self.sdk_chat,
            LegacyAdapterSurface::SdkChatStream => self.sdk_chat_stream,
            LegacyAdapterSurface::SdkEmbeddings => self.sdk_embeddings,
            LegacyAdapterSurface::CompletionChat => self.completion_chat,
            LegacyAdapterSurface::CompletionChatStream => self.completion_chat_stream,
        }
    }
}

const S: LegacyAdapterAvailability = LegacyAdapterAvailability::Supported;
const P: LegacyAdapterAvailability = LegacyAdapterAvailability::Passthrough;
const U: LegacyAdapterAvailability = LegacyAdapterAvailability::Unsupported;
const EXTRA: LegacyAdapterAvailability = LegacyAdapterAvailability::FeatureGated("providers-extra");
const EXTENDED: LegacyAdapterAvailability =
    LegacyAdapterAvailability::FeatureGated("providers-extended");

const CATALOG_HTTP_SUPPORT: ProviderLegacyAdapterSupport = row(
    "catalog_openai_like",
    [P, P, U, U, U, U, U, U, U],
    "Generic Tier 1 catalog providers route through OpenAILike for HTTP chat/stream only.",
);

/// Explicit rows for non-catalog providers and catalog providers with
/// additional legacy completion adapters.
pub static LEGACY_ADAPTER_MATRIX: &[ProviderLegacyAdapterSupport] = &[
    row(
        "v0",
        [U, U, U, U, U, U, U, U, U],
        "Model API contract is no longer published in current docs; default model and protocol unverified.",
    ),
    row(
        "lambda_ai",
        [U, U, U, U, U, U, U, U, U],
        "Shared inference retired on 2025-09-25.",
    ),
    row(
        "meta_llama",
        [U, U, U, U, U, U, U, U, U],
        "Default Llama API transport is not verified against the current Meta Model API.",
    ),
    row(
        "amazon_nova",
        [U, U, U, U, U, U, U, U, U],
        "Default transport is unverified; use native Bedrock for supported Nova models.",
    ),
    row(
        "perplexity",
        [U, U, U, U, U, U, U, U, U],
        "Sonar Chat Completions retired; Agent API has no runtime adapter yet.",
    ),
    row(
        "github",
        [U, U, U, U, U, U, U, U, U],
        "GitHub Models inference service retired on 2026-07-30; Copilot is separate.",
    ),
    row(
        "openai",
        [S, S, S, S, S, S, S, S, S],
        "Reference provider across HTTP, SDK, and completion().",
    ),
    row(
        "anthropic",
        [S, S, U, U, S, S, U, S, S],
        "Native Anthropic chat/stream adapter.",
    ),
    row(
        "azure",
        [P, P, EXTRA, EXTRA, U, U, S, P, P],
        "SDK currently exposes Azure embeddings only.",
    ),
    row(
        "azure_ai",
        [P, P, EXTRA, EXTRA, U, U, U, EXTRA, EXTRA],
        "completion() supports azure_ai/ and azure-ai/ dynamic routes with providers-extra.",
    ),
    row(
        "bedrock",
        [S, S, S, U, U, U, U, U, U],
        "Core Bedrock runtime supports chat, stream, and embeddings; legacy SDK and completion adapters are absent.",
    ),
    row(
        "databricks",
        [P, P, U, U, U, U, U, U, U],
        "Databricks Model Serving OpenAI-compatible chat and SSE.",
    ),
    row(
        "snowflake",
        [P, P, U, U, U, U, U, U, U],
        "Snowflake Cortex OpenAI-compatible chat and SSE.",
    ),
    rerank_row(
        "oci",
        [P, P, S, U, U, U, U, U, U],
        S,
        "OCI compatible mode provides chat/SSE; IAM native mode provides embeddings and rerank.",
    ),
    rerank_row(
        "watsonx",
        [S, U, S, U, U, U, U, U, U],
        S,
        "watsonx native chat, embeddings, and rerank; streaming is not implemented.",
    ),
    row(
        "sagemaker",
        [S, U, U, U, U, U, U, U, U],
        "SageMaker InvokeEndpoint chat requires an explicit supported payload transformer.",
    ),
    row(
        "mistral",
        [S, S, P, U, U, U, U, U, U],
        "Native HTTP provider; legacy SDK/completion adapters are not implemented.",
    ),
    row(
        "cloudflare",
        [S, U, U, U, U, U, U, U, U],
        "Workers AI chat only.",
    ),
    row(
        "deepgram",
        [U, U, U, U, U, U, U, U, U],
        "Native audio routes; this matrix covers chat, embeddings, and images.",
    ),
    row(
        "elevenlabs",
        [U, U, U, U, U, U, U, U, U],
        "Native audio routes; this matrix covers chat, embeddings, and images.",
    ),
    rerank_row(
        "cohere",
        [EXTENDED, EXTENDED, EXTENDED, U, U, U, U, U, U],
        EXTENDED,
        "Native provider is behind providers-extended.",
    ),
    rerank_row(
        "voyage",
        [U, U, S, U, U, U, U, U, U],
        S,
        "Native Voyage embeddings plus the shared HTTP rerank route.",
    ),
    row(
        "vertex_ai",
        [EXTRA, EXTRA, EXTRA, EXTRA, U, U, U, U, U],
        "Native provider is behind providers-extra; SDK GoogleVertex is not implemented.",
    ),
    row(
        "gemini",
        [EXTENDED, EXTENDED, U, U, U, U, U, U, U],
        "Native provider is behind providers-extended; SDK Google chat is not implemented.",
    ),
    row(
        "github_copilot",
        [EXTENDED, EXTENDED, U, U, U, U, U, U, U],
        "Native provider is behind providers-extended; SDK adapter is not implemented.",
    ),
    row(
        "google",
        [U, U, U, U, U, U, U, U, U],
        "SDK Google selector is intentionally unsupported until a real adapter exists.",
    ),
    row(
        "fal_ai",
        [U, U, U, EXTENDED, U, U, U, U, U],
        "Image-generation provider behind providers-extended.",
    ),
    row(
        "stability",
        [U, U, U, EXTENDED, U, U, U, U, U],
        "Native image generation/edit provider behind providers-extended.",
    ),
    row(
        "black_forest_labs",
        [U, U, U, EXTENDED, U, U, U, U, U],
        "Native asynchronous image generation/edit provider behind providers-extended.",
    ),
    row(
        "replicate",
        [EXTENDED, EXTENDED, U, EXTENDED, U, U, U, U, U],
        "Prediction lifecycle provider behind providers-extended.",
    ),
    row(
        "pydantic_ai",
        [U, U, U, U, U, U, U, U, U],
        "ProviderType registry entry is not currently dispatchable.",
    ),
    row(
        "openai_compatible",
        [P, P, P, P, U, U, U, S, S],
        "HTTP chat/embeddings/image generation/audio and completion() OpenAI-compatible passthrough.",
    ),
    row(
        "sdk_custom",
        [U, U, U, U, U, U, S, U, U],
        "SDK custom providers support embeddings when a base_url is configured.",
    ),
    row(
        "ollama",
        [EXTENDED, EXTENDED, EXTENDED, U, U, S, U, U, U],
        "Native HTTP chat, NDJSON streaming, and embeddings require providers-extended; SDK streaming keeps its existing OpenAI-compatible parser.",
    ),
    row(
        "openrouter",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with completion() dynamic route.",
    ),
    row(
        "deepseek",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with completion() dynamic route.",
    ),
    row(
        "moonshot",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with completion() dynamic route.",
    ),
    row(
        "minimax",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with completion() dynamic route.",
    ),
    row(
        "zhipu",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with zhipu/ and glm/ completion() routes.",
    ),
    row(
        "zai",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with zai/ completion() dynamic route.",
    ),
    row(
        "together",
        [P, P, U, U, U, U, U, S, S],
        "Legacy Tier 1 catalog selector with together/ completion() dynamic route.",
    ),
    row(
        "together_ai",
        [P, P, U, U, U, U, U, S, S],
        "LiteLLM Tier 1 catalog selector with together_ai/ completion() dynamic route.",
    ),
    row(
        "fireworks",
        [P, P, U, U, U, U, U, S, S],
        "Legacy Tier 1 catalog selector with fireworks/ completion() dynamic route.",
    ),
    row(
        "fireworks_ai",
        [P, P, U, U, U, U, U, S, S],
        "LiteLLM Tier 1 catalog selector with fireworks_ai/ completion() dynamic route.",
    ),
    row(
        "aiml",
        [P, P, U, U, U, U, U, S, S],
        "LiteLLM Tier 1 catalog selector with aiml/ completion() dynamic route.",
    ),
    row(
        "aiml_api",
        [P, P, U, U, U, U, U, S, S],
        "Legacy Tier 1 catalog selector with aiml_api/ completion() dynamic route.",
    ),
    row(
        "groq",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with completion() dynamic route.",
    ),
    row(
        "xiaomi_mimo",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with xiaomi_mimo/ and mimo/ completion() routes.",
    ),
    row(
        "xai",
        [P, P, U, U, U, U, U, S, S],
        "Tier 1 catalog provider with completion() dynamic route.",
    ),
];

pub fn legacy_adapter_matrix() -> &'static [ProviderLegacyAdapterSupport] {
    LEGACY_ADAPTER_MATRIX
}

pub fn legacy_adapter_availability(
    provider_name: &str,
    surface: LegacyAdapterSurface,
) -> Option<LegacyAdapterAvailability> {
    let selector = canonical_selector(provider_name);

    LEGACY_ADAPTER_MATRIX
        .iter()
        .find(|entry| entry.selector == selector)
        .map(|entry| entry.availability_for(surface))
        .or_else(|| {
            get_definition(&selector).map(|_| CATALOG_HTTP_SUPPORT.availability_for(surface))
        })
}

pub fn supports_legacy_adapter(provider_name: &str, surface: LegacyAdapterSurface) -> bool {
    legacy_adapter_availability(provider_name, surface)
        .map(LegacyAdapterAvailability::is_available_in_current_build)
        .unwrap_or(false)
}

pub fn selector_has_legacy_adapter_entry(provider_name: &str) -> bool {
    let selector = canonical_selector(provider_name);
    LEGACY_ADAPTER_MATRIX
        .iter()
        .any(|entry| entry.selector == selector)
        || get_definition(&selector).is_some()
}

pub fn canonical_selector(provider_name: &str) -> String {
    let lowered = provider_name.trim().to_ascii_lowercase();
    if let Some(entry) = entry_for_name(&lowered) {
        return entry.canonical_name.to_string();
    }
    if let Some(canonical) = canonical_catalog_name(&lowered) {
        return canonical.to_string();
    }

    let normalized = lowered.replace('-', "_");

    match normalized.as_str() {
        "aws_bedrock" => "bedrock".to_string(),
        "google_vertex" => "vertex_ai".to_string(),
        "openai_like" => "openai_compatible".to_string(),
        "custom" => "sdk_custom".to_string(),
        "huggingface" | "hugging_face" => "huggingface".to_string(),
        other => entry_for_name(other)
            .map(|entry| entry.canonical_name.to_string())
            .or_else(|| canonical_catalog_name(other).map(str::to_string))
            .unwrap_or_else(|| other.to_string()),
    }
}

const fn row(
    selector: &'static str,
    support: [LegacyAdapterAvailability; 9],
    notes: &'static str,
) -> ProviderLegacyAdapterSupport {
    ProviderLegacyAdapterSupport {
        selector,
        http_chat: support[0],
        http_chat_stream: support[1],
        http_embeddings: support[2],
        http_rerank: U,
        http_image_generation: support[3],
        sdk_chat: support[4],
        sdk_chat_stream: support[5],
        sdk_embeddings: support[6],
        completion_chat: support[7],
        completion_chat_stream: support[8],
        notes,
    }
}

const fn rerank_row(
    selector: &'static str,
    support: [LegacyAdapterAvailability; 9],
    http_rerank: LegacyAdapterAvailability,
    notes: &'static str,
) -> ProviderLegacyAdapterSupport {
    let mut result = row(selector, support, notes);
    result.http_rerank = http_rerank;
    result
}