diff --git a/litellm/constants.py b/litellm/constants.py
index bbeb4846e27..ad13d57aa42 100644
--- a/litellm/constants.py
+++ b/litellm/constants.py
@@ -210,6 +210,7 @@ LITELLM_UI_ALLOW_HEADERS: Final = [
"x-litellm-guardrail-scan-id",
"x-litellm-guardrail-scan-metadata",
"x-litellm-cache-key",
+ "x-litellm-response-cost",
]
# Gemini model-specific minimal thinking budget constants
diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.py
index 950a6cc3c40..394118dd880 100644
--- a/tests/test_litellm/proxy/test_proxy_server.py
+++ b/tests/test_litellm/proxy/test_proxy_server.py
@@ -103,6 +103,13 @@ def test_cors_exposes_cache_key_header_to_browser_js():
assert "x-litellm-cache-key" in cors_middleware.kwargs["expose_headers"]
+def test_cors_exposes_response_cost_header_to_browser_js():
+ from fastapi.middleware.cors import CORSMiddleware
+
+ cors_middleware = next(m for m in app.user_middleware if m.cls is CORSMiddleware)
+ assert "x-litellm-response-cost" in cors_middleware.kwargs["expose_headers"]
+
+
def test_login_v2_returns_redirect_url_and_sets_cookie(monkeypatch):
mock_login_result = {"user_id": "test-user"}
mock_prisma_client = MagicMock()
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/CostOptimizationView.activity.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/CostOptimizationView.activity.test.tsx
index 03250e3e53b..b3ba951783f 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/CostOptimizationView.activity.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/CostOptimizationView.activity.test.tsx
@@ -37,9 +37,14 @@ vi.mock("@/components/shared/charts", () => ({
SEQUENTIAL_COLOR_RAMP: ["indigo"],
}));
-vi.mock("@/app/(dashboard)/router-settings/_components/general_settings", () => ({
- PromptCachingPanel: () =>
,
-}));
+vi.mock("@/app/(dashboard)/router-settings/_components/general_settings", async (importOriginal) => {
+ const original =
+ await importOriginal();
+ return {
+ ...original,
+ PromptCachingPanel: () => ,
+ };
+});
vi.mock("./PromptCompressionTab", () => ({ __esModule: true, default: () => }));
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.test.tsx
index 66db347e70f..9bba3d5495a 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.test.tsx
@@ -7,11 +7,17 @@ vi.mock("@/components/networking", () => ({
getGeneralSettingsCall: (...args: unknown[]) => mockGetGeneralSettingsCall(...args),
}));
-vi.mock("@/app/(dashboard)/router-settings/_components/general_settings", () => ({
- PromptCachingPanel: () => ,
-}));
+vi.mock("@/app/(dashboard)/router-settings/_components/general_settings", async (importOriginal) => {
+ const original =
+ await importOriginal();
+ return {
+ ...original,
+ PromptCachingPanel: () => ,
+ };
+});
const mockCacheLeakageCard = vi.fn();
+const mockPromptCachingTestCard = vi.fn();
vi.mock("./CacheLeakageCard", () => ({
__esModule: true,
@@ -21,27 +27,72 @@ vi.mock("./CacheLeakageCard", () => ({
},
}));
+vi.mock("./PromptCachingTestCard", () => ({
+ __esModule: true,
+ default: (props: unknown) => {
+ mockPromptCachingTestCard(props);
+ return ;
+ },
+}));
+
import PromptCachingTab from "./PromptCachingTab";
+const activity = {
+ dateValue: {},
+ onDateChange: vi.fn(),
+ results: [],
+ loading: false,
+ isFetchingMore: false,
+ progress: { currentPage: 1, totalPages: 1 },
+ cancelled: false,
+ failed: false,
+ cancel: vi.fn(),
+};
+
describe("PromptCachingTab", () => {
it("renders the cache leakage table alongside the caching settings", async () => {
mockGetGeneralSettingsCall.mockResolvedValue([]);
- const activity = {
- dateValue: {},
- onDateChange: vi.fn(),
- results: [],
- loading: false,
- isFetchingMore: false,
- progress: { currentPage: 1, totalPages: 1 },
- cancelled: false,
- failed: false,
- cancel: vi.fn(),
- };
render();
expect(screen.getByTestId("caching-settings")).toBeInTheDocument();
expect(screen.getByTestId("cache-leakage-card")).toBeInTheDocument();
await waitFor(() => expect(mockCacheLeakageCard).toHaveBeenCalledWith(expect.objectContaining({ activity })));
});
+
+ it("passes enabled=true to the test card when the caching setting is on", async () => {
+ mockGetGeneralSettingsCall.mockResolvedValue([
+ {
+ field_name: "enable_anthropic_prompt_caching",
+ field_type: "Boolean",
+ field_value: true,
+ field_description: "",
+ stored_in_db: true,
+ },
+ ]);
+
+ render();
+
+ await waitFor(() =>
+ expect(mockPromptCachingTestCard).toHaveBeenCalledWith(expect.objectContaining({ enabled: true })),
+ );
+ });
+
+ it("passes enabled=false to the test card when the caching setting is off", async () => {
+ mockGetGeneralSettingsCall.mockResolvedValue([
+ {
+ field_name: "enable_anthropic_prompt_caching",
+ field_type: "Boolean",
+ field_value: false,
+ field_description: "",
+ stored_in_db: true,
+ },
+ ]);
+
+ render();
+
+ await waitFor(() =>
+ expect(mockPromptCachingTestCard).toHaveBeenCalledWith(expect.objectContaining({ enabled: false })),
+ );
+ });
});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.tsx b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.tsx
index 59b38f272e0..dd541d7563b 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTab.tsx
@@ -5,10 +5,13 @@ import React, { useCallback, useEffect, useState } from "react";
import { getGeneralSettingsCall } from "@/components/networking";
import { toast } from "@/lib/toast";
import {
+ ENABLE_ANTHROPIC_PROMPT_CACHING,
PromptCachingPanel,
generalSettingsItem,
+ isOn,
} from "@/app/(dashboard)/router-settings/_components/general_settings";
import CacheLeakageCard from "./CacheLeakageCard";
+import PromptCachingTestCard from "./PromptCachingTestCard";
import { DailyActivityRange } from "./useDailyActivityRange";
interface PromptCachingTabProps {
@@ -45,9 +48,12 @@ const PromptCachingTab: React.FC = ({ accessToken, activi
return null;
}
+ const enableSetting = settings.find((s) => s.field_name === ENABLE_ANTHROPIC_PROMPT_CACHING);
+
return (
);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTestCard.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTestCard.test.tsx
new file mode 100644
index 00000000000..3bb1045c8c1
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/PromptCachingTestCard.test.tsx
@@ -0,0 +1,83 @@
+import { fireEvent, render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+
+vi.mock("@/components/networking", () => ({
+ getProxyBaseUrl: vi.fn(() => "http://proxy:4000"),
+}));
+
+vi.mock("@/components/common_components/ModelSelector", () => ({
+ __esModule: true,
+ default: ({ onChange }: { onChange?: (value: string | null) => void }) => (
+