Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

chore(auto-router): merge main and preserve JEV configuration

Moe Khalilbb46e8b774d8
diff --cc ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx
index c8252408f6b,57a6201bc7b..84e44fee9c3
--- a/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx
+++ b/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx
@@@ -409,7 -407,7 +411,8 @@@ const AddAutoRouterTab: React.FC<AddAut
classificationMode: complexityRouterConfig.classification_mode,
tierLabels: complexityRouterConfig.tier_labels,
classifierType: complexityRouterConfig.classifier_type,
+ jevClassifierConfig: complexityRouterConfig.jev_classifier_config,
+ heuristicV2SuccessThreshold: complexityRouterConfig.heuristic_v2_success_threshold,
capabilityClassifierConfig: complexityRouterConfig.capability_classifier_config,
llmV2Config: complexityRouterConfig.llm_v2_config,
classifierLlmConfig: complexityRouterConfig.classifier_llm_config,
diff --cc ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts
index d21c5a80812,05dc327968c..15ae2b4c0b0
--- a/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts
+++ b/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts
@@@ -367,16 -359,17 +370,22 @@@ export const getKeywordTierRulesError
return `Keyword rule(s) ${orphaned.join(", ")} route to a tier this router no longer has`;
};
+ export const getHeuristicV2SuccessThresholdError = (threshold: number | undefined): string | null => {
+ if (threshold === undefined) return null;
+ const validProbability = Number.isFinite(threshold) && threshold >= 0 && threshold <= 1;
+ return validProbability ? null : "Success threshold must be a number between 0 and 1";
+ };
+
-// An edited tier set forces the LLM classifier, so the model requirement follows the EFFECTIVE type.
-// Both forms' submit gates and their submit handlers read this one answer so they cannot drift.
export const getClassifierModelError = (
- config: Pick<ComplexityRouterConfigValue, "custom_tier_set" | "classifier_type" | "classifier_llm_config">,
+ config: Pick<
+ ComplexityRouterConfigValue,
+ "custom_tier_set" | "classifier_type" | "classifier_llm_config" | "jev_classifier_config"
+ >,
): string | null => {
+ if (effectiveClassifierType(config) === "jev") {
+ const parsed = jevClassifierConfigSchema.safeParse(config.jev_classifier_config ?? {});
+ return parsed.success ? null : "Enter a JEV model, a positive whole-number timeout and a positive cooldown";
+ }
if (!usesLlmClassifier(effectiveClassifierType(config)) || config.classifier_llm_config?.model) return null;
return config.custom_tier_set
? "Please select a classifier model: an edited tier set routes with the LLM classifier"
@@@ -673,7 -650,9 +683,10 @@@ export const buildComplexityRouterConfi
...(planModeMinTier?.trim() && { plan_mode_min_tier: planModeMinTier }),
...(cleanedTierLabels && { tier_labels: cleanedTierLabels }),
classifier_type: classifierType,
+ ...(effectiveType === "jev" && { jev_classifier_config: normalizeJevClassifierConfig(jevClassifierConfig) }),
+ ...(heuristicV2SuccessThreshold !== undefined && {
+ heuristic_v2_success_threshold: heuristicV2SuccessThreshold,
+ }),
...classifierWireFields(effectiveType, classifierInputs),
...(effectiveType === "capability" &&
capabilityClassifierConfig && { capability_classifier_config: capabilityClassifierConfig }),
diff --cc ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts
index 85439d99f21,e4b4cbafdf6..2450f7bce27
--- a/ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts
+++ b/ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts
@@@ -48,101 -46,34 +48,129 @@@ const hydratedState: KeywordMatchingSta
};
describe("buildUpdatedComplexityRouterConfig keyword matching", () => {
+ it.each([false, true])("omits masked JEV credentials from dashboard saves, edited: %s", (edited) => {
+ const stored = {
+ classifier_type: "jev" as const,
+ tiers: FORM_VALUE.tiers,
+ jev_classifier_config: {
+ model: "jev-configured",
+ timeout_ms: 6100,
+ instructions: "Existing instructions",
+ api_key: "sk-s****************cret",
+ api_base: "https://jev.example.com",
+ },
+ };
+ const hydrated = hydrateComplexityRouterConfig(stored, undefined);
+ expect(hydrated.jev_classifier_config).not.toHaveProperty("api_key");
+ expect(hydrated.jev_classifier_config).not.toHaveProperty("api_base");
+ const value = edited
+ ? {
+ ...hydrated,
+ jev_classifier_config: { model: "jev-updated", timeout_ms: 8100, instructions: "" },
+ }
+ : hydrated;
+ const saved = buildUpdatedComplexityRouterConfig(stored, value);
+ expect(saved.jev_classifier_config).toEqual({
+ ...(edited
+ ? { model: "jev-updated", timeout_ms: 8100 }
+ : { model: "jev-configured", timeout_ms: 6100, instructions: "Existing instructions" }),
+ });
+ for (const classifierType of ["llm", "heuristic"] as const) {
+ expect(
+ buildUpdatedComplexityRouterConfig(saved, transitionClassifierType(value, classifierType)),
+ ).not.toHaveProperty("jev_classifier_config");
+ }
+ });
+
+ it("hydrates nullable JEV instructions without resetting the server configuration", () => {
+ const stored = {
+ classifier_type: "jev" as const,
+ jev_classifier_config: {
+ model: "jev-configured",
+ timeout_ms: 6100,
+ instructions: null,
+ circuit_breaker_enabled: false,
+ },
+ tiers: FORM_VALUE.tiers,
+ };
+ const saved = buildUpdatedComplexityRouterConfig(stored, hydrateComplexityRouterConfig(stored, undefined));
+ expect(saved.jev_classifier_config).toEqual({
+ model: "jev-configured",
+ timeout_ms: 6100,
+ circuit_breaker_enabled: false,
+ });
+ });
+ it.each([false, true])("round trips JEV settings and preserves unmanaged fields, custom: %s", (custom) => {
+ const stored = {
+ ...(custom ? storedCustomConfig() : STORED),
+ classifier_llm_config: { model: "stale-judge", timeout_ms: 3000 },
+ classifier_type: "jev" as const,
+ jev_classifier_config: {
+ model: "jev-test",
+ timeout_ms: 4100,
+ instructions: "Judge the request",
+ circuit_breaker_enabled: false,
+ circuit_breaker_cooldown_seconds: 10.5,
+ },
+ classifier_context_window_size: 7,
+ classifier_context_budget_chars: 9000,
+ classifier_context_per_turn_chars: 450,
+ classifier_context_include_assistant_turns: true,
+ some_future_backend_key: { nested: true },
+ };
+ const hydrated = hydrateComplexityRouterConfig(stored, undefined);
+ expect(effectiveClassifierType(hydrated)).toBe("jev");
+ expect(hydrated.classifier_llm_config).toBeUndefined();
+ expect(hydrated.jev_classifier_config).toEqual(stored.jev_classifier_config);
+ expect(hydrated.classifier_context_per_turn_chars).toBe(450);
+ const saved = buildUpdatedComplexityRouterConfig(stored, hydrated);
+ const expectedSavedConfig = {
+ classifier_type: "jev",
+ jev_classifier_config: stored.jev_classifier_config,
+ classifier_context_window_size: 7,
+ classifier_context_budget_chars: 9000,
+ classifier_context_per_turn_chars: 450,
+ classifier_context_include_assistant_turns: true,
+ some_future_backend_key: { nested: true },
+ };
+ expect(saved).toMatchObject(expectedSavedConfig);
+ expect(saved).not.toHaveProperty("classifier_llm_config");
+ const reloaded = hydrateComplexityRouterConfig(saved, undefined);
+ expect(reloaded.jev_classifier_config).toEqual(hydrated.jev_classifier_config);
+ expect(reloaded.classifier_context_per_turn_chars).toBe(450);
+ expect(effectiveClassifierType(reloaded)).toBe("jev");
+ const llm = buildUpdatedComplexityRouterConfig(saved, transitionClassifierType(reloaded, "llm"));
+ expect(llm).not.toHaveProperty("jev_classifier_config");
+ });
+
+ it.each([0, 0.92, 1])("hydrates and saves a success threshold of %s without changing the artifact", (threshold) => {
+ const stored = {
+ ...STORED,
+ classifier_type: "heuristic_v2" as const,
+ heuristic_v2_success_threshold: threshold,
+ heuristic_v2_artifact: { routing_threshold: 0.82, custom_metadata: "retained" },
+ };
+ const hydrated = hydrateComplexityRouterConfig(stored, undefined);
+ expect(hydrated.heuristic_v2_success_threshold).toBe(threshold);
+ const saved = buildUpdatedComplexityRouterConfig(stored, hydrated);
+ expect(saved.heuristic_v2_success_threshold).toBe(threshold);
+ expect(saved.heuristic_v2_artifact).toEqual(stored.heuristic_v2_artifact);
+
+ const cleared = buildUpdatedComplexityRouterConfig(stored, {
+ ...hydrated,
+ heuristic_v2_success_threshold: undefined,
+ });
+ expect(cleared).not.toHaveProperty("heuristic_v2_success_threshold");
+ expect(cleared.heuristic_v2_artifact).toEqual(stored.heuristic_v2_artifact);
+ });
+
+ it.each([undefined, null])("keeps an inherited success threshold %s omitted after saving", (threshold) => {
+ const stored = { ...STORED, heuristic_v2_success_threshold: threshold };
+ const hydrated = hydrateComplexityRouterConfig(stored, undefined);
+ expect(hydrated.heuristic_v2_success_threshold).toBeUndefined();
+ expect(buildUpdatedComplexityRouterConfig(stored, hydrated)).not.toHaveProperty("heuristic_v2_success_threshold");
+ });
+
it.each(["capability", "llm_v2", "heuristic"] as const)(
"handles enabled stored overrides when editing %s with or without keyword form state",
(classifier_type) => {
diff --cc ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx
index 10fa6fcb6be,5991049f4fc..c88bbb101f7
--- a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx
+++ b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx
@@@ -129,14 -128,13 +130,18 @@@ export const hydrateComplexityRouterCon
plan_mode_min_tier: hydratePlanModeMinTier(parsedConfig.plan_mode_min_tier, custom_tier_set),
tier_labels: hydrateTierLabels(parsedConfig.tier_labels),
classifier_type: parsedConfig.classifier_type || "heuristic",
+ heuristic_v2_success_threshold:
+ typeof parsedConfig.heuristic_v2_success_threshold === "number"
+ ? parsedConfig.heuristic_v2_success_threshold
+ : undefined,
capability_classifier_config: capabilitySettingsSchema.safeParse(parsedConfig.capability_classifier_config).data,
llm_v2_config: fuseSettingsSchema.safeParse(parsedConfig.llm_v2_config).data,
- classifier_llm_config: parsedConfig.classifier_llm_config,
+ classifier_llm_config: parsedConfig.classifier_type === "jev" ? undefined : parsedConfig.classifier_llm_config,
+ jev_classifier_config:
+ parsedConfig.classifier_type === "jev"
+ ? jevClassifierConfigSchema.safeParse(parsedConfig.jev_classifier_config ?? {}).data ??
+ defaultJevClassifierConfig()
+ : undefined,
classifier_context_window_size:
typeof parsedConfig.classifier_context_window_size === "number"
? parsedConfig.classifier_context_window_size
@@@ -344,7 -335,7 +350,8 @@@ export const buildUpdatedComplexityRout
classificationMode: value.classification_mode,
tierLabels: value.tier_labels,
classifierType: value.classifier_type,
+ jevClassifierConfig: value.jev_classifier_config,
+ heuristicV2SuccessThreshold: value.heuristic_v2_success_threshold,
capabilityClassifierConfig: value.capability_classifier_config,
llmV2Config: value.llm_v2_config,
classifierLlmConfig: value.classifier_llm_config,
diff --cc ui/litellm-dashboard/src/lib/autorouter_presets.test.ts
index d9e83ab850f,7c49b15e279..e1d9e6ab5ac
--- a/ui/litellm-dashboard/src/lib/autorouter_presets.test.ts
+++ b/ui/litellm-dashboard/src/lib/autorouter_presets.test.ts
@@@ -680,33 -680,17 +680,44 @@@ describe("autorouter_presets", () =>
});
describe("buildPresetPrefill", () => {
+ it("preserves JEV settings and drops inactive classifier settings when prefilling", () => {
+ const config = {
+ tiers: { SIMPLE: ["fast"], MEDIUM: [], COMPLEX: [], REASONING: [] },
+ classifier_type: "jev" as const,
+ classification_mode: "every_request" as const,
+ session_affinity: false,
+ deployment_affinity: true,
+ modality_routing: false,
+ modality_pin_override: false,
+ jev_classifier_config: { model: "jev-test", timeout_ms: 4000, circuit_breaker_enabled: false },
+ classifier_llm_config: { model: "stale-judge", timeout_ms: 6000 },
+ classifier_context_window_size: 6,
+ };
+ const prefill = buildPresetPrefill(config, groupsOnly(["fast"]));
+ const expectedJevConfig = {
+ classifier_type: "jev",
+ jev_classifier_config: config.jev_classifier_config,
+ classifier_context_window_size: 6,
+ classifier_llm_config: undefined,
+ };
+ expect(prefill.complexityRouterConfig).toMatchObject(expectedJevConfig);
+ const llmConfig = { ...config, classifier_type: "llm" as const };
+ const llmPrefill = buildPresetPrefill(llmConfig, groupsOnly(["fast"]));
+ expect(llmPrefill.complexityRouterConfig.jev_classifier_config).toBeUndefined();
+ expect(llmPrefill.complexityRouterConfig.classifier_llm_config).toEqual(config.classifier_llm_config);
+ });
+
+ it.each([undefined, 0, 0.95])("carries a preset's success threshold %s into the form", (threshold) => {
+ const preset = getPresetByKey("anthropic_family")!;
+ const config = {
+ ...preset.complexity_router_config,
+ classifier_type: "heuristic_v2" as const,
+ heuristic_v2_success_threshold: threshold,
+ };
+ const prefill = buildPresetPrefill(config, groupsOnly(getRequiredModelsInPreset(preset)));
+ expect(prefill.complexityRouterConfig.heuristic_v2_success_threshold).toBe(threshold);
+ });
+
it("prefills a real bundled preset's tiers into the config", () => {
const preset = getPresetByKey("anthropic_family")!;
const prefill = buildPresetPrefill(
diff --cc ui/litellm-dashboard/src/lib/autorouter_presets.ts
index 728c1e53574,f085b4760a9..8cf461d77b9
--- a/ui/litellm-dashboard/src/lib/autorouter_presets.ts
+++ b/ui/litellm-dashboard/src/lib/autorouter_presets.ts
@@@ -284,11 -284,11 +284,12 @@@ export const buildPresetPrefill =
tier_model_params: resolveParamKeys(hydrateTierModelParams(config.tiers, config.tier_model_configs)),
tier_labels: hydrateTierLabels(config.tier_labels),
classifier_type: config.classifier_type,
+ heuristic_v2_success_threshold: config.heuristic_v2_success_threshold,
- classifier_llm_config: config.classifier_llm_config && {
- ...config.classifier_llm_config,
- model: resolve(config.classifier_llm_config.model),
- },
+ jev_classifier_config: config.classifier_type === "jev" ? config.jev_classifier_config : undefined,
+ classifier_llm_config:
+ config.classifier_type !== "jev" && config.classifier_llm_config
+ ? { ...config.classifier_llm_config, model: resolve(config.classifier_llm_config.model) }
+ : undefined,
classifier_context_window_size: config.classifier_context_window_size,
classifier_context_budget_chars: config.classifier_context_budget_chars,
classifier_context_per_turn_chars: config.classifier_context_per_turn_chars,