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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_/ui-ux-patterns-audit-1d04bc
Yuneng Jiang75abe09f47f1
diff --cc ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsxindex 030b41f634d,9ef8350553b..73364306a4f--- a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx+++ b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx@@@ -706,3 -706,76 +706,78 @@@ describe("ComplexityRouterConfig affiniexpect(screen.getByRole("switch", { name: "Pin a session to one deployment per model group" })).not.toBeChecked();});});++ describe("ComplexityRouterConfig default model", () => {+ const getDefaultModelSelect = () => screen.getByRole("combobox", { name: "Default model" });++ it("shows what the tiers currently imply, so an untouched router still names its default", () => {+ renderWithProviders(<ComplexityRouterConfig {...baseProps} />);+ expect(screen.getByText("Derived from tiers: gpt-3.5-turbo")).toBeInTheDocument();+ });++ it("asks for a model rather than naming a derived one when no tier holds one", () => {+ const noTiers: ComplexityRouterConfigValue = {+ ...defaultValue,+ tiers: { SIMPLE: [], MEDIUM: [], COMPLEX: [], REASONING: [] },+ };+ renderWithProviders(<ComplexityRouterConfig {...baseProps} value={noTiers} />);+ expect(screen.getByText("Add a model to the Simple or Medium tier")).toBeInTheDocument();+ });++ it("records a pinned model", async () => {+ const user = userEvent.setup();+ const onChange = vi.fn();+ renderWithProviders(<ComplexityRouterConfig {...baseProps} onChange={onChange} />);++ await user.click(getDefaultModelSelect());+ await user.click((await screen.findAllByTitle("claude-3-opus")).slice(-1)[0]);++ expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ default_model: "claude-3-opus" }));+ });++ it("drops the key when the pin is cleared, so an emptied select reads as tier-tracking", async () => {+ const user = userEvent.setup();+ const onChange = vi.fn();+ const pinned: ComplexityRouterConfigValue = { ...defaultValue, default_model: "claude-3-opus" };+ renderWithProviders(<ComplexityRouterConfig {...baseProps} value={pinned} onChange={onChange} />);+++ // eslint-disable-next-line local/no-antd-class-selectors -- antd marks the clear affordance aria-hidden, so no accessible query reaches it+ await user.click(document.querySelector(".ant-select-clear") as HTMLElement);++ expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ default_model: undefined }));+ });++ it("shows a pinned model as the selection instead of the tier-derived one", () => {+ const pinned: ComplexityRouterConfigValue = { ...defaultValue, default_model: "claude-3-opus" };+ renderWithProviders(<ComplexityRouterConfig {...baseProps} value={pinned} />);+ expect(++ // eslint-disable-next-line local/no-antd-class-selectors -- the tier selects show the same model as a tag, so the assertion has to scope to this select's root, which antd exposes only as a class+ within(getDefaultModelSelect().closest(".ant-select") as HTMLElement).getByTitle("claude-3-opus"),+ ).toBeInTheDocument();+ });++ it("unlocks the default model fallback on a pin alone, with no tier to derive from", () => {+ const pinnedNoTiers: ComplexityRouterConfigValue = {+ ...defaultValue,+ classifier_type: "llm",+ classifier_llm_config: { model: "gpt-3.5-turbo", timeout_ms: 3000 },+ tiers: { SIMPLE: [], MEDIUM: [], COMPLEX: [], REASONING: [] },+ default_model: "claude-3-opus",+ };+ renderWithProviders(<ComplexityRouterConfig {...baseProps} value={pinnedNoTiers} />);+ fireEvent.click(screen.getByText("Advanced: Classification Method"));+ expect(screen.getByRole("radio", { name: /Route to the default model/ })).toBeEnabled();+ });++ it("names the resolved default on the fallback option, so the destination is not a guess", () => {+ const pinned: ComplexityRouterConfigValue = {+ ...defaultValue,+ classifier_type: "llm",+ classifier_llm_config: { model: "gpt-3.5-turbo", timeout_ms: 3000 },+ default_model: "claude-3-opus",+ };+ renderWithProviders(<ComplexityRouterConfig {...baseProps} value={pinned} />);+ fireEvent.click(screen.getByText("Advanced: Classification Method"));+ expect(screen.getByRole("radio", { name: /Route to the default model \(claude-3-opus\)/ })).toBeInTheDocument();+ });+ });diff --cc ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsxindex efc1d77871e,6e71f64bcbd..a949b37791b--- a/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsx+++ b/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsx@@@ -350,9 -349,11 +350,9 @@@ describe("AddAutoRouterTab", () =>renderWithProviders(<Harness />);openTemplateDropdown();- const labels = Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option")).map(- (option) => option.querySelector(".font-medium")?.textContent,- );+ const labels = visibleOptions().map((option) => option.querySelector(".font-medium")?.textContent);- expect(labels).toEqual(["Anthropic Family", "OpenAI Family", "Custom Configuration"]);+ expect(labels).toEqual(["Anthropic Family", "Lite", "OpenAI Family", "Custom Configuration"]);});describe("routing test", () => {@@@ -669,8 -735,10 +734,8 @@@await waitFor(() => {expect(isOptionDisabled(optionByLabel("Anthropic Family")!)).toBe(false);});- const labels = Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option")).map(- (option) => option.querySelector(".font-medium")?.textContent,- );+ const labels = visibleOptions().map((option) => option.querySelector(".font-medium")?.textContent);- expect(labels).toEqual(["Anthropic Family", "OpenAI Family", "Custom Configuration"]);+ expect(labels).toEqual(["Anthropic Family", "Lite", "OpenAI Family", "Custom Configuration"]);});it.each([diff --cc ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsxindex 254a34abf40,b38d5492a45..f8a6f671de0--- a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx+++ b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx@@@ -60,6 -60,6 +60,10 @@@ const savedConfig = () =>return payload?.litellm_params?.complexity_router_config;};++const selectedValueIn = (combobox: HTMLElement): string | null =>++ // eslint-disable-next-line local/no-antd-class-selectors -- antd keeps the rendered selection in a sibling of the combobox, reachable only through these classes; the tier selects show the same models, so an unscoped title query is ambiguous++ combobox.closest(".ant-select")?.querySelector(".ant-select-selection-item")?.getAttribute("title") ?? null;++describe("EditAutoRouterModal keyword matching", () => {beforeEach(() => {modelPatchUpdateCall.mockClear();@@@ -549,3 -548,197 +553,195 @@@ describe("EditAutoRouterModal custom clexpect(savedConfig().classifier_llm_config).not.toHaveProperty("system_prompt");});});++ describe("EditAutoRouterModal default model", () => {+ beforeEach(() => {+ modelPatchUpdateCall.mockClear();+ });++ const savedDefaultModel = () => {+ const [, payload] = modelPatchUpdateCall.mock.calls.at(-1) ?? [];+ return payload?.litellm_params?.complexity_router_default_model;+ };++ const renderWithStoredPin = (default_model?: string) =>+ renderWithProviders(+ <EditAutoRouterModal+ isVisible+ onCancel={vi.fn()}+ onSuccess={vi.fn()}+ modelData={{+ ...MODEL_DATA,+ litellm_params: {+ ...MODEL_DATA.litellm_params,+ complexity_router_config: { ...STORED_CONFIG, ...(default_model && { default_model }) },+ },+ }}+ accessToken="token"+ userRole="Admin"+ />,+ );++ // No config blob marker — only litellm_params.complexity_router_default_model, as an untouched+ // router looked before this PR's marker existed, or one an external API call wrote directly to.+ const renderWithLitellmParamsDefaultOnly = (complexityRouterDefaultModel: string) =>+ renderWithProviders(+ <EditAutoRouterModal+ isVisible+ onCancel={vi.fn()}+ onSuccess={vi.fn()}+ modelData={{+ ...MODEL_DATA,+ litellm_params: {+ ...MODEL_DATA.litellm_params,+ complexity_router_config: STORED_CONFIG,+ complexity_router_default_model: complexityRouterDefaultModel,+ },+ }}+ accessToken="token"+ userRole="Admin"+ />,+ );++ it("preserves a stored pin through an untouched open-and-save", async () => {+ const user = userEvent.setup();+ renderWithStoredPin("out-of-band-default");++ await user.click(await screen.findByRole("button", { name: /save changes/i }));++ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());+ expect(savedDefaultModel()).toBe("out-of-band-default");+ expect(savedConfig()).toMatchObject({ default_model: "out-of-band-default" });+ });++ it("shows a stored pin as the selection, so the saved value is not a hidden one", async () => {+ renderWithStoredPin("out-of-band-default");++ const select = await screen.findByRole("combobox", { name: "Default model" });- expect(within(select.closest(".ant-select") as HTMLElement).getByTitle("out-of-band-default")).toBeInTheDocument();++ expect(selectedValueIn(select)).toBe("out-of-band-default");+ });++ // The pin is recorded in the config rather than inferred by comparing the stored default to a+ // re-derivation, so pinning the model the tiers already imply still reads back as a pin.+ it("keeps a pin that matches what the tiers derive", async () => {+ const user = userEvent.setup();+ renderWithStoredPin(STORED_CONFIG.tiers.MEDIUM[0]);++ const select = await screen.findByRole("combobox", { name: "Default model" });- expect(- within(select.closest(".ant-select") as HTMLElement).getByTitle(STORED_CONFIG.tiers.MEDIUM[0]),- ).toBeInTheDocument();++ expect(selectedValueIn(select)).toBe(STORED_CONFIG.tiers.MEDIUM[0]);++ await user.click(screen.getByRole("button", { name: /save changes/i }));+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());+ expect(savedConfig()).toMatchObject({ default_model: STORED_CONFIG.tiers.MEDIUM[0] });+ });++ // Greptile P1 on #36615: with no config blob marker, a litellm_params default that merely+ // matches what the tiers derive is indistinguishable from the pre-PR auto-derive-and-write+ // behavior (main always wrote a tier-derived value there on every save). Treating it as a pin+ // would freeze every pre-existing router's default away from its tiers, so it stays unpinned.+ it("treats a litellm_params default matching tier-derivation as unpinned, not a frozen-in pin", async () => {+ const user = userEvent.setup();+ renderWithLitellmParamsDefaultOnly(STORED_CONFIG.tiers.MEDIUM[0]);++ const select = await screen.findByRole("combobox", { name: "Default model" });- expect(select.closest(".ant-select")?.querySelector(".ant-select-selection-item")).toBeNull();++ expect(selectedValueIn(select)).toBeNull();++ await user.click(screen.getByRole("button", { name: /save changes/i }));+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());+ expect(savedConfig()).not.toHaveProperty("default_model");+ expect(savedDefaultModel()).toBe(STORED_CONFIG.tiers.MEDIUM[0]);+ });++ // Greptile P1 on #36615: a litellm_params default that diverges from tier-derivation could only+ // have gotten there via an explicit override — set by the API directly, since this UI's own+ // save path keeps it in sync with tiers whenever there's no pin. That divergence must survive+ // the next save instead of being silently recomputed away.+ it("treats a diverging litellm_params default as an external pin and preserves it", async () => {+ const user = userEvent.setup();+ renderWithLitellmParamsDefaultOnly("claude-sonnet-4");++ const select = await screen.findByRole("combobox", { name: "Default model" });- expect(within(select.closest(".ant-select") as HTMLElement).getByTitle("claude-sonnet-4")).toBeInTheDocument();++ expect(selectedValueIn(select)).toBe("claude-sonnet-4");++ await user.click(screen.getByRole("button", { name: /save changes/i }));+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());+ expect(savedConfig()).toMatchObject({ default_model: "claude-sonnet-4" });+ expect(savedDefaultModel()).toBe("claude-sonnet-4");+ });++ // The config blob marker is this UI's own authoritative record of intent (see+ // hydratePinnedDefaultModel), so it wins even over a litellm_params value that disagrees —+ // e.g. a stale value from before the operator most recently changed the pin.+ it("prefers the config blob marker over a diverging litellm_params value", async () => {+ const user = userEvent.setup();+ renderWithProviders(+ <EditAutoRouterModal+ isVisible+ onCancel={vi.fn()}+ onSuccess={vi.fn()}+ modelData={{+ ...MODEL_DATA,+ litellm_params: {+ ...MODEL_DATA.litellm_params,+ complexity_router_config: { ...STORED_CONFIG, default_model: "blob-pin" },+ complexity_router_default_model: "stale-litellm-params-value",+ },+ }}+ accessToken="token"+ userRole="Admin"+ />,+ );++ const select = await screen.findByRole("combobox", { name: "Default model" });- expect(within(select.closest(".ant-select") as HTMLElement).getByTitle("blob-pin")).toBeInTheDocument();++ expect(selectedValueIn(select)).toBe("blob-pin");++ await user.click(screen.getByRole("button", { name: /save changes/i }));+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());+ expect(savedConfig()).toMatchObject({ default_model: "blob-pin" });+ });++ // This modal only requires one non-empty tier, so a COMPLEX-only router is reachable here even+ // though the backend raises on it. The block keeps that failure at save time instead of init.+ it("blocks a save when neither the tiers nor a pin give the backend a default", async () => {+ const user = userEvent.setup();+ renderWithProviders(+ <EditAutoRouterModal+ isVisible+ onCancel={vi.fn()}+ onSuccess={vi.fn()}+ modelData={{+ ...MODEL_DATA,+ litellm_params: {+ ...MODEL_DATA.litellm_params,+ complexity_router_config: {+ ...STORED_CONFIG,+ tiers: { SIMPLE: [], MEDIUM: [], COMPLEX: ["complex-model"], REASONING: [] },+ },+ },+ }}+ accessToken="token"+ userRole="Admin"+ />,+ );++ await user.click(await screen.findByRole("button", { name: /save changes/i }));++ await waitFor(() =>+ expect(NotificationsManager.fromBackend).toHaveBeenCalledWith(expect.stringContaining("Simple or Medium tier")),+ );+ expect(modelPatchUpdateCall).not.toHaveBeenCalled();+ });++ it("leaves a router with no stored pin tracking its tiers", async () => {+ const user = userEvent.setup();+ renderWithStoredPin();++ const select = await screen.findByRole("combobox", { name: "Default model" });- expect(select.closest(".ant-select")?.querySelector(".ant-select-selection-item")).toBeNull();++ expect(selectedValueIn(select)).toBeNull();++ await user.click(screen.getByRole("button", { name: /save changes/i }));+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());+ expect(savedDefaultModel()).toBe(STORED_CONFIG.tiers.MEDIUM[0]);+ expect(savedConfig()).not.toHaveProperty("default_model");+ });+ });