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
refactor(ui): invalidate proxyConfig query after spend-logs mutations
Ryan Crabbe325c74548df6
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.test.tsindex a8ce55d2745..4ba80df5c6c 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.test.ts+++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.test.ts@@ -7,6 +7,7 @@ import {useDeleteProxyConfigField,getProxyConfigCall,deleteProxyConfigFieldCall,+ proxyConfigKeys,ConfigType,GeneralSettingsFieldName,type ProxyConfigResponse,@@ -426,6 +427,28 @@ describe("useDeleteProxyConfigField", () => {expect(result.current.error).toBeDefined();});++ it("should invalidate proxyConfig queries after a successful delete", async () => {+ (fetchSpy as any).mockResolvedValue({+ ok: true,+ json: async () => mockDeleteResponse,+ });++ const invalidateSpy = vi.spyOn(queryClient, "invalidateQueries");++ const { result } = renderHook(() => useDeleteProxyConfigField(), { wrapper });++ result.current.mutate({+ config_type: ConfigType.GENERAL_SETTINGS,+ field_name: GeneralSettingsFieldName.MAXIMUM_SPEND_LOGS_RETENTION_PERIOD,+ });++ await waitFor(() => {+ expect(result.current.isSuccess).toBe(true);+ });++ expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: proxyConfigKeys.all });+ });});describe("getProxyConfigCall", () => {diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.tsindex b823ce4ffd8..485c7cc1f92 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.ts+++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/proxyConfig/useProxyConfig.ts@@ -1,4 +1,4 @@-import { useQuery, useMutation, UseMutationResult } from "@tanstack/react-query";+import { useQuery, useMutation, UseMutationResult, useQueryClient } from "@tanstack/react-query";import { createQueryKeys } from "../common/queryKeysFactory";import useAuthorized from "../useAuthorized";import { proxyBaseUrl, getGlobalLitellmHeaderName, deriveErrorMessage, handleError } from "@/components/networking";@@ -101,7 +101,7 @@ export const getProxyConfigCall = async (accessToken: string, configType: Config}};-const proxyConfigKeys = createQueryKeys("proxyConfig");+export const proxyConfigKeys = createQueryKeys("proxyConfig");/*** Network call function to delete a proxy config field@@ -168,6 +168,7 @@ export const useDeleteProxyConfigField = (): UseMutationResult<DeleteProxyConfigFieldRequest> => {const { accessToken } = useAuthorized();+ const queryClient = useQueryClient();return useMutation<DeleteProxyConfigFieldResponse, Error, DeleteProxyConfigFieldRequest>({mutationFn: async (request: DeleteProxyConfigFieldRequest) => {@@ -176,5 +177,8 @@ export const useDeleteProxyConfigField = (): UseMutationResult<}return await deleteProxyConfigFieldCall(accessToken, request);},+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: proxyConfigKeys.all });+ },});};diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/storeRequestInSpendLogs/useStoreRequestInSpendLogs.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/storeRequestInSpendLogs/useStoreRequestInSpendLogs.tsindex 9c6211c3086..67b52997a01 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/storeRequestInSpendLogs/useStoreRequestInSpendLogs.ts+++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/storeRequestInSpendLogs/useStoreRequestInSpendLogs.ts@@ -1,6 +1,7 @@-import { useMutation, UseMutationResult } from "@tanstack/react-query";+import { useMutation, UseMutationResult, useQueryClient } from "@tanstack/react-query";import { getProxyBaseUrl, getGlobalLitellmHeaderName } from "@/components/networking";import useAuthorized from "../useAuthorized";+import { proxyConfigKeys } from "../proxyConfig/useProxyConfig";export interface StoreRequestInSpendLogsParams {store_prompts_in_spend_logs: boolean;@@ -51,6 +52,7 @@ export const useStoreRequestInSpendLogs = (): UseMutationResult<StoreRequestInSpendLogsParams> => {const { accessToken } = useAuthorized();+ const queryClient = useQueryClient();return useMutation<StoreRequestInSpendLogsResponse, Error, StoreRequestInSpendLogsParams>({mutationFn: async (params: StoreRequestInSpendLogsParams) => {@@ -59,5 +61,8 @@ export const useStoreRequestInSpendLogs = (): UseMutationResult<}return await performStoreRequestInSpendLogs(accessToken, params);},+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: proxyConfigKeys.all });+ },});};