diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 0e4696e44..824c40de1 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -914,3 +914,22 @@ async def delete_verification_token(tokens: List, user_id: Optional[str] = None) verbose_proxy_logger.debug(traceback.format_exc()) raise e return deleted_tokens + + +@router.get( + "/litellm_header_name", + include_in_schema=False, +) +async def get_litellm_header_name(): + """ + Used by LiteLLM Admin UI + + returns the header name that should be used for the Authorization header on requests to litellm + """ + from litellm.proxy.proxy_server import general_settings + + if "litellm_key_header_name" in general_settings: + return {"litellm_key_header_name": general_settings["litellm_key_header_name"]} + else: + # default value + return {"litellm_key_header_name": "Authorization"} diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index f31e26d4d..8527b39a2 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -36,6 +36,32 @@ const handleError = async (errorData: string) => { } }; + +export const getLiteLLMHeaderName = async () => { + try { + const url = proxyBaseUrl ? `${proxyBaseUrl}/litellm_header_name` : '/litellm_header_name'; + const response = await fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + console.log('Received LiteLLM header name:', data); + return data.litellm_key_header_name; + } catch (error) { + console.error('Failed to get LiteLLM header name:', error); + throw error; + } +}; + +const litellm_key_header_name = getLiteLLMHeaderName(); + export const modelCostMap = async ( accessToken: string, ) => { @@ -45,7 +71,7 @@ export const modelCostMap = async ( url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, } @@ -68,7 +94,7 @@ export const modelCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -107,7 +133,7 @@ export const modelSettingsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -138,7 +164,7 @@ export const modelDeleteCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -180,7 +206,7 @@ export const budgetDeleteCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -215,7 +241,7 @@ export const budgetCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -251,7 +277,7 @@ export const invitationCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -290,7 +316,7 @@ export const invitationClaimCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -328,7 +354,7 @@ export const alertingSettingsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -385,7 +411,7 @@ export const keyCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -447,7 +473,7 @@ export const userCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -481,7 +507,7 @@ export const keyDeleteCall = async (accessToken: String, user_key: String) => { const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -513,7 +539,7 @@ export const teamDeleteCall = async (accessToken: String, teamID: String) => { const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -566,7 +592,7 @@ export const userInfoCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -601,7 +627,7 @@ export const teamInfoCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -633,7 +659,7 @@ export const getTotalSpendCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -698,7 +724,7 @@ export const claimOnboardingToken = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -740,7 +766,7 @@ export const modelInfoCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -788,7 +814,7 @@ export const modelHubCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -819,7 +845,7 @@ export const getAllowedIPs = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -848,7 +874,7 @@ export const addAllowedIP = async (accessToken: String, ip: String) => { const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ ip: ip }), @@ -878,7 +904,7 @@ export const deleteAllowedIP = async (accessToken: String, ip: String) => { const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ ip: ip }), @@ -920,7 +946,7 @@ export const modelMetricsCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -959,7 +985,7 @@ export const streamingModelMetricsCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1004,7 +1030,7 @@ export const modelMetricsSlowResponsesCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1048,7 +1074,7 @@ export const modelExceptionsCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1083,7 +1109,7 @@ export const modelAvailableCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1113,7 +1139,7 @@ export const keySpendLogsCall = async (accessToken: String, token: String) => { const response = await fetch(`${url}?api_key=${token}`, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1141,7 +1167,7 @@ export const teamSpendLogsCall = async (accessToken: String) => { const response = await fetch(`${url}`, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1184,7 +1210,7 @@ export const tagsSpendLogsCall = async ( const response = await fetch(`${url}`, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1212,7 +1238,7 @@ export const allTagNamesCall = async (accessToken: String) => { const response = await fetch(`${url}`, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1240,7 +1266,7 @@ export const allEndUsersCall = async (accessToken: String) => { const response = await fetch(`${url}`, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1278,7 +1304,7 @@ export const userSpendLogsCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1308,7 +1334,7 @@ export const adminSpendLogsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1338,7 +1364,7 @@ export const adminTopKeysCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1386,14 +1412,14 @@ export const adminTopEndUsersCall = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; "Content-Type": string; }; body?: string; // The body is optional and might not be present } = { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }; @@ -1439,12 +1465,12 @@ export const adminspendByProvider = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; }; } = { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, }, }; @@ -1482,12 +1508,12 @@ export const adminGlobalActivity = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; }; } = { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, }, }; @@ -1523,12 +1549,12 @@ export const adminGlobalCacheActivity = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; }; } = { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, }, }; @@ -1564,12 +1590,12 @@ export const adminGlobalActivityPerModel = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; }; } = { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, }, }; @@ -1610,12 +1636,12 @@ export const adminGlobalActivityExceptions = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; }; } = { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, }, }; @@ -1656,12 +1682,12 @@ export const adminGlobalActivityExceptionsPerDeployment = async ( const requestOptions: { method: string; headers: { - Authorization: string; + litellm_key_header_name: string; }; } = { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, }, }; @@ -1690,7 +1716,7 @@ export const adminTopModelsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1717,7 +1743,7 @@ export const keyInfoCall = async (accessToken: String, keys: String[]) => { const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1747,7 +1773,7 @@ export const spendUsersCall = async (accessToken: String, userID: String) => { const response = await fetch(`${url}?user_id=${userID}`, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1779,7 +1805,7 @@ export const userRequestModelCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1814,7 +1840,7 @@ export const userGetRequesedtModelsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1854,7 +1880,7 @@ export const userGetAllUsersCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1883,7 +1909,7 @@ export const getPossibleUserRoles = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1912,7 +1938,7 @@ export const teamCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1948,7 +1974,7 @@ export const keyUpdateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1983,7 +2009,7 @@ export const teamUpdateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2018,7 +2044,7 @@ export const modelUpdateCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2062,7 +2088,7 @@ export const teamMemberAddCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2105,7 +2131,7 @@ export const userUpdateUserCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: response_body, @@ -2143,7 +2169,7 @@ export const PredictedSpendLogsCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2179,7 +2205,7 @@ export const slackBudgetAlertsHealthCheck = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2218,7 +2244,7 @@ export const serviceHealthCheck = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2253,7 +2279,7 @@ export const getBudgetList = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2286,7 +2312,7 @@ export const getBudgetSettings = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2324,7 +2350,7 @@ export const getCallbacksCall = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2355,7 +2381,7 @@ export const getGeneralSettingsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2389,7 +2415,7 @@ export const getConfigFieldSetting = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2427,7 +2453,7 @@ export const updateConfigFieldSetting = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify(formData), @@ -2467,7 +2493,7 @@ export const deleteConfigFieldSetting = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify(formData), @@ -2502,7 +2528,7 @@ export const setCallbacksCall = async ( const response = await fetch(url, { method: "POST", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2537,7 +2563,7 @@ export const healthCheckCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2573,7 +2599,7 @@ export const getProxyBaseUrlAndLogoutUrl = async ( const response = await fetch(url, { method: "GET", headers: { - Authorization: `Bearer ${accessToken}`, + litellm_key_header_name: `Bearer ${accessToken}`, "Content-Type": "application/json", }, });