Repository navigation
feat(ui): working Test Connection for the complexity auto router #32950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akapur99
merged 3 commits into
litellm_internal_staging
from
litellm_auto_router_test_connection
Jul 12, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ui/litellm-dashboard/src/components/add_model/auto_router_connection_test.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { renderWithProviders, screen, waitFor } from "../../../tests/test-utils"; | ||
| import { vi } from "vitest"; | ||
| import AutoRouterConnectionTest from "./auto_router_connection_test"; | ||
| import { AutoRouterTestTarget } from "./build_auto_router_test_targets"; | ||
|
|
||
| vi.mock("../networking", async () => { | ||
| const actual = await vi.importActual("../networking"); | ||
| return { | ||
| ...actual, | ||
| testConnectionRequest: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| const getMock = async () => vi.mocked((await import("../networking")).testConnectionRequest); | ||
|
|
||
| const targets: AutoRouterTestTarget[] = [ | ||
| { labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }, | ||
| { labels: ["MEDIUM", "COMPLEX"], modelGroup: "claude-sonnet-4", mode: "chat" }, | ||
| { labels: ["Embedding"], modelGroup: "voyage-3-5", mode: "embedding" }, | ||
| ]; | ||
|
|
||
| describe("AutoRouterConnectionTest", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("probes each target once with the right model and mode (chat for tiers, embedding for the embedding model)", async () => { | ||
| const mock = await getMock(); | ||
| mock.mockResolvedValue({ status: "success" }); | ||
|
|
||
| renderWithProviders(<AutoRouterConnectionTest accessToken="sk-test" targets={targets} />); | ||
|
|
||
| await waitFor(() => expect(mock).toHaveBeenCalledTimes(3)); | ||
|
|
||
| expect(mock).toHaveBeenCalledWith("sk-test", { model: "gpt-4o-mini" }, {}, "chat"); | ||
| expect(mock).toHaveBeenCalledWith("sk-test", { model: "claude-sonnet-4" }, {}, "chat"); | ||
| expect(mock).toHaveBeenCalledWith("sk-test", { model: "voyage-3-5" }, {}, "embedding"); | ||
| }); | ||
|
|
||
| it("shows a success indicator per target when the health check passes", async () => { | ||
| const mock = await getMock(); | ||
| mock.mockResolvedValue({ status: "success" }); | ||
|
|
||
| renderWithProviders(<AutoRouterConnectionTest accessToken="sk-test" targets={targets} />); | ||
|
|
||
| await waitFor(() => expect(screen.getAllByTestId("test-status-success")).toHaveLength(3)); | ||
| expect(screen.queryByTestId("test-status-error")).toBeNull(); | ||
| expect(screen.getByText("MEDIUM, COMPLEX")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders the provider error message for a failing target while others pass", async () => { | ||
| const mock = await getMock(); | ||
| mock.mockImplementation((_token, litellmParams) => | ||
| litellmParams.model === "claude-sonnet-4" | ||
| ? Promise.resolve({ status: "error", result: { error: "litellm.AuthenticationError: invalid api key" } }) | ||
| : Promise.resolve({ status: "success" }), | ||
| ); | ||
|
|
||
| renderWithProviders(<AutoRouterConnectionTest accessToken="sk-test" targets={targets} />); | ||
|
|
||
| await waitFor(() => expect(screen.getByTestId("test-error-message")).toBeInTheDocument()); | ||
| expect(screen.getByTestId("test-error-message")).toHaveTextContent("invalid api key"); | ||
| expect(screen.getByTestId("test-error-message")).not.toHaveTextContent("litellm.AuthenticationError"); | ||
| expect(screen.getAllByTestId("test-status-success")).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("surfaces a thrown network error as a failing row", async () => { | ||
| const mock = await getMock(); | ||
| mock.mockRejectedValue(new Error("Network request failed")); | ||
|
|
||
| renderWithProviders( | ||
| <AutoRouterConnectionTest | ||
| accessToken="sk-test" | ||
| targets={[{ labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }]} | ||
| />, | ||
| ); | ||
|
|
||
| await waitFor(() => expect(screen.getByTestId("test-error-message")).toHaveTextContent("Network request failed")); | ||
| }); | ||
| }); |
132 changes: 132 additions & 0 deletions
132
ui/litellm-dashboard/src/components/add_model/auto_router_connection_test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import React from "react"; | ||
| import { Typography } from "antd"; | ||
| import { CheckCircleTwoTone, CloseCircleTwoTone, LoadingOutlined } from "@ant-design/icons"; | ||
| import { testConnectionRequest } from "../networking"; | ||
| import { AutoRouterTestTarget } from "./build_auto_router_test_targets"; | ||
|
|
||
| const { Text } = Typography; | ||
|
|
||
| interface AutoRouterConnectionTestProps { | ||
| accessToken: string; | ||
| targets: AutoRouterTestTarget[]; | ||
| onTestComplete?: () => void; | ||
| } | ||
|
|
||
| type TargetResult = { status: "pending" } | { status: "success" } | { status: "error"; error: string }; | ||
|
|
||
| interface NormalizedResponse { | ||
| ok: boolean; | ||
| error?: string; | ||
| } | ||
|
|
||
| const normalizeTestConnectionResponse = (response: unknown): NormalizedResponse => { | ||
| if (typeof response !== "object" || response === null) { | ||
| return { ok: false, error: "Unexpected response from connection test" }; | ||
| } | ||
| const record = response as Record<string, unknown>; | ||
| if (record.status === "success") { | ||
| return { ok: true }; | ||
| } | ||
| const result = | ||
| typeof record.result === "object" && record.result !== null ? (record.result as Record<string, unknown>) : {}; | ||
| const resultError = typeof result.error === "string" ? result.error : undefined; | ||
| const recordMessage = typeof record.message === "string" ? record.message : undefined; | ||
| return { ok: false, error: resultError ?? recordMessage ?? "Unknown error" }; | ||
| }; | ||
|
|
||
| const cleanErrorMessage = (error: string): string => { | ||
| const mainError = error.split("stack trace:")[0].trim(); | ||
| return mainError.replace(/^litellm\.(.*?)Error: /, ""); | ||
| }; | ||
|
|
||
| const runTarget = async (accessToken: string, target: AutoRouterTestTarget): Promise<TargetResult> => { | ||
| try { | ||
| const response = await testConnectionRequest(accessToken, { model: target.modelGroup }, {}, target.mode); | ||
| const normalized = normalizeTestConnectionResponse(response); | ||
| return normalized.ok | ||
| ? { status: "success" } | ||
| : { status: "error", error: cleanErrorMessage(normalized.error ?? "Unknown error") }; | ||
| } catch (error) { | ||
| return { status: "error", error: cleanErrorMessage(error instanceof Error ? error.message : String(error)) }; | ||
| } | ||
| }; | ||
|
|
||
| const AutoRouterConnectionTest: React.FC<AutoRouterConnectionTestProps> = ({ | ||
| accessToken, | ||
| targets, | ||
| onTestComplete, | ||
| }) => { | ||
| const [results, setResults] = React.useState<TargetResult[]>(() => targets.map(() => ({ status: "pending" }))); | ||
|
|
||
| React.useEffect(() => { | ||
| let cancelled = false; | ||
| const run = async () => { | ||
| const settled = await Promise.all(targets.map((target) => runTarget(accessToken, target))); | ||
| if (cancelled) return; | ||
| setResults(settled); | ||
| if (onTestComplete) onTestComplete(); | ||
| }; | ||
| run(); | ||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps -- probes run once per mount; the parent remounts via `key` to start a fresh test, and re-running on prop identity changes would refire paid health checks | ||
| }, []); | ||
|
|
||
| if (targets.length === 0) { | ||
| return <Text type="secondary">No complexity tiers are configured yet, so there is nothing to test.</Text>; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="space-y-3"> | ||
| <Text type="secondary" style={{ display: "block", marginBottom: 8 }}> | ||
| Each configured tier routes to a saved model group. Test Connection runs a live health check against each one. | ||
| </Text> | ||
| {targets.map((target, index) => { | ||
| const result = results[index] ?? { status: "pending" }; | ||
| return ( | ||
| <div | ||
| key={`${target.modelGroup}-${target.mode}`} | ||
| data-testid="auto-router-test-row" | ||
| style={{ | ||
| border: "1px solid #e5e7eb", | ||
| borderRadius: 8, | ||
| padding: "12px 16px", | ||
| display: "flex", | ||
| alignItems: "flex-start", | ||
| gap: 12, | ||
| }} | ||
| > | ||
| <div style={{ fontSize: 18, lineHeight: "24px" }}> | ||
| {result.status === "pending" && <LoadingOutlined data-testid="test-status-pending" />} | ||
| {result.status === "success" && ( | ||
| <CheckCircleTwoTone twoToneColor="#52c41a" data-testid="test-status-success" /> | ||
| )} | ||
| {result.status === "error" && ( | ||
| <CloseCircleTwoTone twoToneColor="#ff4d4f" data-testid="test-status-error" /> | ||
| )} | ||
| </div> | ||
| <div style={{ flex: 1 }}> | ||
| <Text strong>{target.labels.join(", ")}</Text>{" "} | ||
| <Text type="secondary"> | ||
| {"->"} {target.modelGroup} | ||
| {target.mode === "embedding" ? " (embedding)" : ""} | ||
| </Text> | ||
| {result.status === "error" && ( | ||
| <Text | ||
| type="danger" | ||
| data-testid="test-error-message" | ||
| style={{ display: "block", marginTop: 4, fontSize: 13 }} | ||
| > | ||
| {result.error} | ||
| </Text> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AutoRouterConnectionTest; | ||
68 changes: 68 additions & 0 deletions
68
ui/litellm-dashboard/src/components/add_model/build_auto_router_test_targets.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { buildAutoRouterTestTargets } from "./build_auto_router_test_targets"; | ||
|
|
||
| const tiers = { | ||
| SIMPLE: "gpt-4o-mini", | ||
| MEDIUM: "claude-sonnet-4", | ||
| COMPLEX: "claude-sonnet-4", | ||
| REASONING: "o3", | ||
| }; | ||
|
|
||
| describe("buildAutoRouterTestTargets", () => { | ||
| it("dedups tiers that share a model group into one chat target carrying both labels", () => { | ||
| const targets = buildAutoRouterTestTargets({ tiers, semanticMatchingEnabled: false, embeddingModel: undefined }); | ||
| expect(targets).toEqual([ | ||
| { labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }, | ||
| { labels: ["MEDIUM", "COMPLEX"], modelGroup: "claude-sonnet-4", mode: "chat" }, | ||
| { labels: ["REASONING"], modelGroup: "o3", mode: "chat" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("drops empty/whitespace tiers", () => { | ||
| const targets = buildAutoRouterTestTargets({ | ||
| tiers: { SIMPLE: "gpt-4o-mini", MEDIUM: "", COMPLEX: " ", REASONING: "" }, | ||
| semanticMatchingEnabled: false, | ||
| embeddingModel: undefined, | ||
| }); | ||
| expect(targets).toEqual([{ labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }]); | ||
| }); | ||
|
|
||
| it("returns [] when no tier is configured", () => { | ||
| expect( | ||
| buildAutoRouterTestTargets({ | ||
| tiers: { SIMPLE: "", MEDIUM: "", COMPLEX: "", REASONING: "" }, | ||
| semanticMatchingEnabled: false, | ||
| embeddingModel: undefined, | ||
| }), | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it("appends an embedding target only when semantic matching is on and a model is set", () => { | ||
| const targets = buildAutoRouterTestTargets({ | ||
| tiers: { SIMPLE: "gpt-4o-mini", MEDIUM: "", COMPLEX: "", REASONING: "" }, | ||
| semanticMatchingEnabled: true, | ||
| embeddingModel: "voyage-3-5", | ||
| }); | ||
| expect(targets).toEqual([ | ||
| { labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }, | ||
| { labels: ["Embedding"], modelGroup: "voyage-3-5", mode: "embedding" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("omits the embedding target when semantic matching is on but no model is chosen", () => { | ||
| const targets = buildAutoRouterTestTargets({ | ||
| tiers: { SIMPLE: "gpt-4o-mini", MEDIUM: "", COMPLEX: "", REASONING: "" }, | ||
| semanticMatchingEnabled: true, | ||
| embeddingModel: undefined, | ||
| }); | ||
| expect(targets).toEqual([{ labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }]); | ||
| }); | ||
|
|
||
| it("omits the embedding target when a model is set but semantic matching is off", () => { | ||
| const targets = buildAutoRouterTestTargets({ | ||
| tiers: { SIMPLE: "gpt-4o-mini", MEDIUM: "", COMPLEX: "", REASONING: "" }, | ||
| semanticMatchingEnabled: false, | ||
| embeddingModel: "voyage-3-5", | ||
| }); | ||
| expect(targets).toEqual([{ labels: ["SIMPLE"], modelGroup: "gpt-4o-mini", mode: "chat" }]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.