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
fix(ui): ignore stale playground model loads on key switch
mubashir1osmani5102b9c0d83d
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.test.tsxindex 5407fa7e66c..f9db7710593 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.test.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.test.tsx@@ -117,39 +117,6 @@ describe("ChatUI", () => {});});- it("shows all models returned for the active key regardless of endpoint", async () => {- (fetchModelsModule.fetchAvailableModels as ReturnType<typeof vi.fn>).mockResolvedValueOnce([- { model_group: "ChatModel", mode: "chat" },- { model_group: "SpeechModel", mode: "audio_speech" },- { model_group: "ImageModel", mode: "image_generation" },- { model_group: "ResponsesModel", mode: "responses" },- ]);-- render(- <ChatUI- accessToken="1234567890"- token="1234567890"- userRole="user"- userID="1234567890"- disabledPersonalKeyCreation={false}- />,- );-- await waitFor(() => {- expect(screen.getByText("Test Key")).toBeInTheDocument();- });-- await selectComboboxOption("Select an endpoint", "/v1/chat/completions");- await openComboboxByPlaceholder("Select a Model");-- await waitFor(() => {- expect(screen.getAllByText("ChatModel").length).toBeGreaterThan(0);- expect(screen.getAllByText("SpeechModel").length).toBeGreaterThan(0);- expect(screen.getAllByText("ImageModel").length).toBeGreaterThan(0);- expect(screen.getAllByText("ResponsesModel").length).toBeGreaterThan(0);- });- });-it("should show 'Enter custom model' option in model selector", async () => {render(<ChatUIdiff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.tsxindex ce6880fbb30..f6e1b9fbcf6 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/chat_ui/ChatUI.tsx@@ -408,34 +408,45 @@ const ChatUI: React.FC<ChatUIProps> = ({return;}+ let cancelled = false;+const loadModels = async () => {setIsLoadingModels(true);setModelLoadError(false);try {const uniqueModels = await fetchAvailableModels(userApiKey);+ if (cancelled) {+ return;+ }setModelInfo(uniqueModels);- // check for selection overlap or empty model listconst hasSelection = uniqueModels.some((m) => m.model_group === selectedModel);- if (!uniqueModels.length) {- setSelectedModel(undefined);- } else if (!hasSelection) {+ if (!uniqueModels.length || !hasSelection) {setSelectedModel(undefined);}} catch (error) {+ if (cancelled) {+ return;+ }console.error("Error fetching model info:", error);setModelInfo([]);setModelLoadError(true);} finally {- setIsLoadingModels(false);+ if (!cancelled) {+ setIsLoadingModels(false);+ }}};if (!simplified) {- loadModels();+ void loadModels();}- loadMCPServers();+ void loadMCPServers();++ return () => {+ cancelled = true;+ };}, [accessToken, apiKeySource, apiKey, simplified]);// Load tools when MCP direct mode has a server (or toolset) selected