Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(litellm): enhance validation of LiteLLM connection credentials to handle 404 status for admin keys

Victor Hugo dos Santos8758c8c53258
diff --git a/backend/src/services/app-connection/litellm/litellm-connection-fns.ts b/backend/src/services/app-connection/litellm/litellm-connection-fns.ts
index dc79a53d9c..5e8104dedc 100644
--- a/backend/src/services/app-connection/litellm/litellm-connection-fns.ts
+++ b/backend/src/services/app-connection/litellm/litellm-connection-fns.ts
@@ -18,15 +18,24 @@ export const getLiteLLMConnectionListItem = () => {
export const validateLiteLLMConnectionCredentials = async (config: TLiteLLMConnectionConfig) => {
const { apiKey, instanceUrl } = config.credentials;
const baseUrl = removeTrailingSlash(instanceUrl);
+ const headers = { Authorization: `Bearer ${apiKey}` };
// safeRequest guards the user-supplied host against SSRF (blocks localhost/private IPs outside of dev mode)
try {
- await safeRequest.get(`${baseUrl}/key/info`, {
- headers: {
- Authorization: `Bearer ${apiKey}`
- },
- validateStatus: (status) => status === 200
+ const { status } = await safeRequest.get(`${baseUrl}/key/info`, {
+ headers,
+ validateStatus: (code) => code === 200 || code === 404
});
+
+ // The proxy master key is read from LITELLM_MASTER_KEY and has no row in LiteLLM's key table, so
+ // /key/info authenticates it but then 404s. /user/list confirms it is a valid admin key instead.
+ if (status === 404) {
+ await safeRequest.get(`${baseUrl}/user/list`, {
+ headers,
+ params: { page_size: 1 },
+ validateStatus: (code) => code === 200
+ });
+ }
} catch (error: unknown) {
logger.error(
{ errorMessage: error instanceof Error ? error.message : "Unknown error" },