From 548adea8cf11b36fe5dfa0b80f9dd0f46db6de04 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 26 Jul 2024 21:04:31 -0700 Subject: [PATCH 1/4] add litellm_header_name endpoint --- .../key_management_endpoints.py | 19 ++ .../src/components/networking.tsx | 176 ++++++++++-------- 2 files changed, 120 insertions(+), 75 deletions(-) diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 0e4696e4423..824c40de1a9 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 f31e26d4d92..8527b39a295 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", }, }); From d71dc1acaf57108d4b2a5a45b8713b5d6fcbb1c0 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 16:58:56 -0700 Subject: [PATCH 2/4] ui use setGlobalLitellmHeaderName --- ui/litellm-dashboard/src/app/page.tsx | 6 + .../src/components/networking.tsx | 180 ++++++++---------- 2 files changed, 89 insertions(+), 97 deletions(-) diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx index 26bdb7af24a..9b7a09cbfd7 100644 --- a/ui/litellm-dashboard/src/app/page.tsx +++ b/ui/litellm-dashboard/src/app/page.tsx @@ -18,6 +18,7 @@ import Usage from "../components/usage"; import CacheDashboard from "@/components/cache_dashboard"; import { jwtDecode } from "jwt-decode"; import { Typography } from "antd"; +import { setGlobalLitellmHeaderName } from "../components/networking" function getCookie(name: string) { console.log("COOKIES", document.cookie) @@ -123,6 +124,11 @@ const CreateKeyPage = () => { if (decoded.premium_user) { setPremiumUser(decoded.premium_user); } + + if (decoded.auth_header_name) { + setGlobalLitellmHeaderName(decoded.auth_header_name); + } + } } }, [token]); diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index 8527b39a295..b196d3c2e34 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -37,30 +37,15 @@ 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', - }, - }); +// Global variable for the header name +let globalLitellmHeaderName: string | null = null; - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } +// Function to set the global header name +export function setGlobalLitellmHeaderName(headerName: string | null) { + console.log(`setGlobalLitellmHeaderName: ${headerName}`); + globalLitellmHeaderName = headerName; +} - 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, @@ -71,7 +56,7 @@ export const modelCostMap = async ( url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, } @@ -94,7 +79,7 @@ export const modelCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -133,7 +118,7 @@ export const modelSettingsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -164,7 +149,7 @@ export const modelDeleteCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -206,7 +191,7 @@ export const budgetDeleteCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -241,7 +226,7 @@ export const budgetCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -277,7 +262,7 @@ export const invitationCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -316,7 +301,7 @@ export const invitationClaimCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -354,7 +339,7 @@ export const alertingSettingsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -411,7 +396,7 @@ export const keyCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -473,7 +458,7 @@ export const userCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -507,7 +492,7 @@ export const keyDeleteCall = async (accessToken: String, user_key: String) => { const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -539,7 +524,7 @@ export const teamDeleteCall = async (accessToken: String, teamID: String) => { const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -592,7 +577,7 @@ export const userInfoCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -627,7 +612,7 @@ export const teamInfoCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -659,7 +644,7 @@ export const getTotalSpendCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -724,7 +709,7 @@ export const claimOnboardingToken = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -766,7 +751,7 @@ export const modelInfoCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -814,7 +799,7 @@ export const modelHubCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -845,7 +830,7 @@ export const getAllowedIPs = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -874,7 +859,7 @@ export const addAllowedIP = async (accessToken: String, ip: String) => { const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ ip: ip }), @@ -904,7 +889,7 @@ export const deleteAllowedIP = async (accessToken: String, ip: String) => { const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ ip: ip }), @@ -946,7 +931,7 @@ export const modelMetricsCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -985,7 +970,7 @@ export const streamingModelMetricsCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1030,7 +1015,7 @@ export const modelMetricsSlowResponsesCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1074,7 +1059,7 @@ export const modelExceptionsCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1102,6 +1087,7 @@ export const modelAvailableCall = async ( /** * Get all the models user has access to */ + console.log("in /models calls, globalLitellmHeaderName", globalLitellmHeaderName) try { let url = proxyBaseUrl ? `${proxyBaseUrl}/models` : `/models`; @@ -1109,7 +1095,7 @@ export const modelAvailableCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1139,7 +1125,7 @@ export const keySpendLogsCall = async (accessToken: String, token: String) => { const response = await fetch(`${url}?api_key=${token}`, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1167,7 +1153,7 @@ export const teamSpendLogsCall = async (accessToken: String) => { const response = await fetch(`${url}`, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1210,7 +1196,7 @@ export const tagsSpendLogsCall = async ( const response = await fetch(`${url}`, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1238,7 +1224,7 @@ export const allTagNamesCall = async (accessToken: String) => { const response = await fetch(`${url}`, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1266,7 +1252,7 @@ export const allEndUsersCall = async (accessToken: String) => { const response = await fetch(`${url}`, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1304,7 +1290,7 @@ export const userSpendLogsCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1334,7 +1320,7 @@ export const adminSpendLogsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1364,7 +1350,7 @@ export const adminTopKeysCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1412,14 +1398,14 @@ export const adminTopEndUsersCall = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; "Content-Type": string; }; body?: string; // The body is optional and might not be present } = { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }; @@ -1465,12 +1451,12 @@ export const adminspendByProvider = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; }; } = { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, }, }; @@ -1508,12 +1494,12 @@ export const adminGlobalActivity = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; }; } = { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, }, }; @@ -1549,12 +1535,12 @@ export const adminGlobalCacheActivity = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; }; } = { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, }, }; @@ -1590,12 +1576,12 @@ export const adminGlobalActivityPerModel = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; }; } = { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, }, }; @@ -1636,12 +1622,12 @@ export const adminGlobalActivityExceptions = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; }; } = { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, }, }; @@ -1682,12 +1668,12 @@ export const adminGlobalActivityExceptionsPerDeployment = async ( const requestOptions: { method: string; headers: { - litellm_key_header_name: string; + [globalLitellmHeaderName]: string; }; } = { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, }, }; @@ -1716,7 +1702,7 @@ export const adminTopModelsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1743,7 +1729,7 @@ export const keyInfoCall = async (accessToken: String, keys: String[]) => { const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1773,7 +1759,7 @@ export const spendUsersCall = async (accessToken: String, userID: String) => { const response = await fetch(`${url}?user_id=${userID}`, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1805,7 +1791,7 @@ export const userRequestModelCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1840,7 +1826,7 @@ export const userGetRequesedtModelsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1880,7 +1866,7 @@ export const userGetAllUsersCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1909,7 +1895,7 @@ export const getPossibleUserRoles = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -1938,7 +1924,7 @@ export const teamCreateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -1974,7 +1960,7 @@ export const keyUpdateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2009,7 +1995,7 @@ export const teamUpdateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2044,7 +2030,7 @@ export const modelUpdateCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2088,7 +2074,7 @@ export const teamMemberAddCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2131,7 +2117,7 @@ export const userUpdateUserCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: response_body, @@ -2169,7 +2155,7 @@ export const PredictedSpendLogsCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2205,7 +2191,7 @@ export const slackBudgetAlertsHealthCheck = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2244,7 +2230,7 @@ export const serviceHealthCheck = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2279,7 +2265,7 @@ export const getBudgetList = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2312,7 +2298,7 @@ export const getBudgetSettings = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2350,7 +2336,7 @@ export const getCallbacksCall = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2381,7 +2367,7 @@ export const getGeneralSettingsCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2415,7 +2401,7 @@ export const getConfigFieldSetting = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2453,7 +2439,7 @@ export const updateConfigFieldSetting = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify(formData), @@ -2493,7 +2479,7 @@ export const deleteConfigFieldSetting = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify(formData), @@ -2528,7 +2514,7 @@ export const setCallbacksCall = async ( const response = await fetch(url, { method: "POST", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ @@ -2563,7 +2549,7 @@ export const healthCheckCall = async (accessToken: String) => { const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); @@ -2599,7 +2585,7 @@ export const getProxyBaseUrlAndLogoutUrl = async ( const response = await fetch(url, { method: "GET", headers: { - litellm_key_header_name: `Bearer ${accessToken}`, + [globalLitellmHeaderName]: `Bearer ${accessToken}`, "Content-Type": "application/json", }, }); From f25ed92ee29ab7e6b6ace05f5a015c294d3e9af5 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 16:59:15 -0700 Subject: [PATCH 3/4] better debugging for custom headers --- litellm/proxy/auth/user_api_key_auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index d91baf5cad8..c4401a2cf53 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -1310,8 +1310,9 @@ def get_api_key_from_custom_header( # use this as the virtual key passed to litellm proxy custom_litellm_key_header_name = custom_litellm_key_header_name.lower() verbose_proxy_logger.debug( - "searching for custom_litellm_key_header_name= %s", + "searching for custom_litellm_key_header_name= %s, in headers=%s", custom_litellm_key_header_name, + request.headers, ) custom_api_key = request.headers.get(custom_litellm_key_header_name) if custom_api_key: From 0c25aaf9dfcd47e512035afc2584aa88a1802c7d Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 17:03:04 -0700 Subject: [PATCH 4/4] check litellm header in login on ui --- .../key_management_endpoints.py | 19 ------------------- litellm/proxy/proxy_server.py | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 824c40de1a9..0e4696e4423 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -914,22 +914,3 @@ 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/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 1f35a06f0a2..41078130b72 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7773,7 +7773,7 @@ async def fallback_login(request: Request): "/login", include_in_schema=False ) # hidden since this is a helper for UI sso login async def login(request: Request): - global premium_user + global premium_user, general_settings try: import multipart except ImportError: @@ -7875,6 +7875,9 @@ async def login(request: Request): "user_role": user_role, # this is the path without sso - we can assume only admins will use this "login_method": "username_password", "premium_user": premium_user, + "auth_header_name": general_settings.get( + "litellm_key_header_name", "Authorization" + ), }, master_key, algorithm="HS256", @@ -7939,6 +7942,9 @@ async def login(request: Request): "user_role": user_role, "login_method": "username_password", "premium_user": premium_user, + "auth_header_name": general_settings.get( + "litellm_key_header_name", "Authorization" + ), }, master_key, algorithm="HS256", @@ -7987,7 +7993,7 @@ async def onboarding(invite_link: str): - Get user from db - Pass in user_email if set """ - global prisma_client, master_key + global prisma_client, master_key, general_settings if master_key is None: raise ProxyException( message="Master Key not set for Proxy. Please set Master Key to use Admin UI. Set `LITELLM_MASTER_KEY` in .env or set general_settings:master_key in config.yaml. https://docs.litellm.ai/docs/proxy/virtual_keys. If set, use `--detailed_debug` to debug issue.", @@ -8074,6 +8080,9 @@ async def onboarding(invite_link: str): "user_role": user_obj.user_role, "login_method": "username_password", "premium_user": premium_user, + "auth_header_name": general_settings.get( + "litellm_key_header_name", "Authorization" + ), }, master_key, algorithm="HS256", @@ -8491,6 +8500,9 @@ async def auth_callback(request: Request): "user_role": user_role, "login_method": "sso", "premium_user": premium_user, + "auth_header_name": general_settings.get( + "litellm_key_header_name", "Authorization" + ), }, master_key, algorithm="HS256",