Skip to content

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]

Add ability to see which model cost map is getting used

Sameer Kankute262235f2667a
diff --git a/litellm/litellm_core_utils/get_model_cost_map.py b/litellm/litellm_core_utils/get_model_cost_map.py
index e622a317454..f9398979f97 100644
--- a/litellm/litellm_core_utils/get_model_cost_map.py
+++ b/litellm/litellm_core_utils/get_model_cost_map.py
@@ -11,6 +11,7 @@ export LITELLM_LOCAL_MODEL_COST_MAP=True
import json
import os
from importlib.resources import files
+from typing import Optional
import httpx
@@ -151,6 +152,37 @@ class GetModelCostMap:
return response.json()
+class ModelCostMapSourceInfo:
+ """Tracks the source of the currently loaded model cost map."""
+
+ source: str = "local" # "local" or "remote"
+ url: Optional[str] = None
+ is_env_forced: bool = False
+ fallback_reason: Optional[str] = None
+
+
+# Module-level singleton tracking the source of the current cost map
+_cost_map_source_info = ModelCostMapSourceInfo()
+
+
+def get_model_cost_map_source_info() -> dict:
+ """
+ Return metadata about where the current model cost map was loaded from.
+
+ Returns a dict with:
+ - source: "local" or "remote"
+ - url: the remote URL attempted (or None for local-only)
+ - is_env_forced: True if LITELLM_LOCAL_MODEL_COST_MAP=True forced local usage
+ - fallback_reason: human-readable reason if remote failed and local was used
+ """
+ return {
+ "source": _cost_map_source_info.source,
+ "url": _cost_map_source_info.url,
+ "is_env_forced": _cost_map_source_info.is_env_forced,
+ "fallback_reason": _cost_map_source_info.fallback_reason,
+ }
+
+
def get_model_cost_map(url: str) -> dict:
"""
Public entry point — returns the model cost map dict.
@@ -166,8 +198,15 @@ def get_model_cost_map(url: str) -> dict:
# Note: can't use get_secret_bool here — this runs during litellm.__init__
# before litellm._key_management_settings is set.
if os.getenv("LITELLM_LOCAL_MODEL_COST_MAP", "").lower() == "true":
+ _cost_map_source_info.source = "local"
+ _cost_map_source_info.url = None
+ _cost_map_source_info.is_env_forced = True
+ _cost_map_source_info.fallback_reason = None
return GetModelCostMap.load_local_model_cost_map()
+ _cost_map_source_info.url = url
+ _cost_map_source_info.is_env_forced = False
+
try:
content = GetModelCostMap.fetch_remote_model_cost_map(url)
except Exception as e:
@@ -177,6 +216,8 @@ def get_model_cost_map(url: str) -> dict:
url,
str(e),
)
+ _cost_map_source_info.source = "local"
+ _cost_map_source_info.fallback_reason = f"Remote fetch failed: {str(e)}"
return GetModelCostMap.load_local_model_cost_map()
# Validate using cached count (cheap int comparison, no file I/O)
@@ -189,6 +230,10 @@ def get_model_cost_map(url: str) -> dict:
"Using local backup instead. url=%s",
url,
)
+ _cost_map_source_info.source = "local"
+ _cost_map_source_info.fallback_reason = "Remote data failed integrity validation"
return GetModelCostMap.load_local_model_cost_map()
+ _cost_map_source_info.source = "remote"
+ _cost_map_source_info.fallback_reason = None
return content
diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx
index a618988fa1a..38065e72965 100644
--- a/ui/litellm-dashboard/src/components/networking.tsx
+++ b/ui/litellm-dashboard/src/components/networking.tsx
@@ -466,6 +466,33 @@ export const cancelModelCostMapReload = async (accessToken: string) => {
}
};
+export const getModelCostMapSource = async (accessToken: string) => {
+ try {
+ const url = proxyBaseUrl
+ ? `${proxyBaseUrl}/model/cost_map/source`
+ : `/model/cost_map/source`;
+ const response = await fetch(url, {
+ method: "GET",
+ headers: {
+ [globalLitellmHeaderName]: `Bearer ${accessToken}`,
+ "Content-Type": "application/json",
+ },
+ });
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(`HTTP ${response.status}: ${errorText}`);
+ }
+
+ const jsonData = await response.json();
+ console.log("Model cost map source info:", jsonData);
+ return jsonData;
+ } catch (error) {
+ console.error("Failed to get model cost map source info:", error);
+ throw error;
+ }
+};
+
export const getModelCostMapReloadStatus = async (accessToken: string) => {
try {
const url = proxyBaseUrl
diff --git a/ui/litellm-dashboard/src/components/price_data_reload.tsx b/ui/litellm-dashboard/src/components/price_data_reload.tsx
index 4609c0cd929..f8b0ab24c36 100644
--- a/ui/litellm-dashboard/src/components/price_data_reload.tsx
+++ b/ui/litellm-dashboard/src/components/price_data_reload.tsx
@@ -1,11 +1,12 @@
import React, { useState, useEffect } from "react";
-import { Button, Popconfirm, Modal, InputNumber, Space, Typography, Tag, Card } from "antd";
-import { ReloadOutlined, ClockCircleOutlined, StopOutlined } from "@ant-design/icons";
+import { Button, Popconfirm, Modal, InputNumber, Space, Typography, Tag, Card, Tooltip, Divider } from "antd";
+import { ReloadOutlined, ClockCircleOutlined, StopOutlined, CloudOutlined, DatabaseOutlined, InfoCircleOutlined, WarningOutlined } from "@ant-design/icons";
import {
reloadModelCostMap,
scheduleModelCostMapReload,
cancelModelCostMapReload,
getModelCostMapReloadStatus,
+ getModelCostMapSource,
} from "./networking";
import NotificationsManager from "./molecules/notifications_manager";
@@ -18,6 +19,14 @@ interface ReloadStatus {
next_run: string | null;
}
+interface CostMapSourceInfo {
+ source: "local" | "remote";
+ url: string | null;
+ is_env_forced: boolean;
+ fallback_reason: string | null;
+ model_count: number;
+}
+
interface PriceDataReloadProps {
accessToken: string;
onReloadSuccess?: () => void;
@@ -44,14 +53,18 @@ const PriceDataReload: React.FC<PriceDataReloadProps> = ({
const [hours, setHours] = useState<number>(6);
const [reloadStatus, setReloadStatus] = useState<ReloadStatus | null>(null);
const [loadingStatus, setLoadingStatus] = useState(false);
+ const [sourceInfo, setSourceInfo] = useState<CostMapSourceInfo | null>(null);
+ const [loadingSource, setLoadingSource] = useState(false);
// Fetch status on component mount and periodically
useEffect(() => {
fetchReloadStatus();
+ fetchSourceInfo();
// Refresh status every 30 seconds to keep it up to date
const interval = setInterval(() => {
fetchReloadStatus();
+ fetchSourceInfo();
}, 30000);
return () => clearInterval(interval);
@@ -80,6 +93,20 @@ const PriceDataReload: React.FC<PriceDataReloadProps> = ({
}
};
+ const fetchSourceInfo = async () => {
+ if (!accessToken) return;
+
+ setLoadingSource(true);
+ try {
+ const info = await getModelCostMapSource(accessToken);
+ setSourceInfo(info);
+ } catch (error) {
+ console.error("Failed to fetch cost map source info:", error);
+ } finally {
+ setLoadingSource(false);
+ }
+ };
+
const handleHardRefresh = async () => {
if (!accessToken) {
NotificationsManager.fromBackend("No access token available");
@@ -93,8 +120,9 @@ const PriceDataReload: React.FC<PriceDataReloadProps> = ({
if (response.status === "success") {
NotificationsManager.success(`Price data reloaded successfully! ${response.models_count || 0} models updated.`);
onReloadSuccess?.();
- // Refresh status after successful reload
+ // Refresh status and source info after successful reload
await fetchReloadStatus();
+ await fetchSourceInfo();
} else {
NotificationsManager.fromBackend("Failed to reload price data");
}
@@ -284,7 +312,108 @@ const PriceDataReload: React.FC<PriceDataReloadProps> = ({
)}
</Space>
- {/* Status Card */}
+ {/* Cost Map Source Info Card */}
+ {sourceInfo && (
+ <Card
+ size="small"
+ style={{
+ backgroundColor: sourceInfo.source === "remote" ? "#f0f7ff" : "#fff8f0",
+ border: `1px solid ${sourceInfo.source === "remote" ? "#bae0ff" : "#ffd591"}`,
+ borderRadius: 8,
+ marginBottom: 12,
+ }}
+ >
+ <Space direction="vertical" size="small" style={{ width: "100%" }}>
+ {/* Header row */}
+ <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
+ {sourceInfo.source === "remote" ? (
+ <CloudOutlined style={{ color: "#1677ff", fontSize: 16 }} />
+ ) : (
+ <DatabaseOutlined style={{ color: "#fa8c16", fontSize: 16 }} />
+ )}
+ <Text strong style={{ fontSize: "13px" }}>
+ Pricing Data Source
+ </Text>
+ <Tag
+ color={sourceInfo.source === "remote" ? "blue" : "orange"}
+ style={{ marginLeft: "auto", fontWeight: 600, textTransform: "uppercase", fontSize: "11px" }}
+ >
+ {sourceInfo.source === "remote" ? "Remote" : "Local"}
+ </Tag>
+ </div>
+
+ <Divider style={{ margin: "6px 0" }} />
+
+ {/* Model count */}
+ <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
+ <Text type="secondary" style={{ fontSize: "12px" }}>
+ Models loaded:
+ </Text>
+ <Text strong style={{ fontSize: "12px" }}>
+ {sourceInfo.model_count.toLocaleString()}
+ </Text>
+ </div>
+
+ {/* URL (when remote or attempted) */}
+ {sourceInfo.url && (
+ <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: 8 }}>
+ <Text type="secondary" style={{ fontSize: "12px", whiteSpace: "nowrap" }}>
+ {sourceInfo.source === "remote" ? "Loaded from:" : "Attempted URL:"}
+ </Text>
+ <Tooltip title={sourceInfo.url}>
+ <Text
+ style={{
+ fontSize: "11px",
+ maxWidth: 240,
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ display: "block",
+ color: "#1677ff",
+ cursor: "default",
+ }}
+ >
+ {sourceInfo.url}
+ </Text>
+ </Tooltip>
+ </div>
+ )}
+
+ {/* Env forced notice */}
+ {sourceInfo.is_env_forced && (
+ <div style={{ display: "flex", alignItems: "center", gap: 6, marginTop: 2 }}>
+ <InfoCircleOutlined style={{ color: "#fa8c16", fontSize: 12 }} />
+ <Text type="secondary" style={{ fontSize: "11px" }}>
+ Local mode forced via <code>LITELLM_LOCAL_MODEL_COST_MAP=True</code>
+ </Text>
+ </div>
+ )}
+
+ {/* Fallback reason */}
+ {sourceInfo.fallback_reason && (
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-start",
+ gap: 6,
+ backgroundColor: "#fff7e6",
+ border: "1px solid #ffd591",
+ borderRadius: 4,
+ padding: "4px 8px",
+ marginTop: 2,
+ }}
+ >
+ <WarningOutlined style={{ color: "#fa8c16", fontSize: 12, marginTop: 2 }} />
+ <Text style={{ fontSize: "11px", color: "#614700" }}>
+ Fell back to local: {sourceInfo.fallback_reason}
+ </Text>
+ </div>
+ )}
+ </Space>
+ </Card>
+ )}
+
+ {/* Reload Schedule Status Card */}
{reloadStatus && (
<Card
size="small"