fix(router): fail closed on missing named credentials

This commit is contained in:
Yujong Lee 2026-08-30 18:55:08 -07:00 committed by GitHub
parent 8c252d7b73
commit 413cb8076c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -9635,6 +9635,7 @@ class Router:
verbose_router_logger.warning(
"Credential '%s' not found in credential_list", deployment.litellm_params.litellm_credential_name
)
return None
credentials.update(credential_values)
# Remove the credential name since we've resolved it
credentials.pop("litellm_credential_name", None)

View file

@ -241,6 +241,7 @@ class CredentialLiteLLMParams(BaseModel):
api_key: str | None = None
api_base: str | None = None
api_version: str | None = None
project_id: str | None = None
## AZURE OAUTH ##
# Without this field, ``get_deployment_credentials_with_provider``
# round-trips ``litellm_params`` through a strict Pydantic dump and

View file

@ -4539,6 +4539,45 @@ def test_get_deployment_credentials_with_provider_resolves_credential_name():
litellm.credential_list = []
def test_get_deployment_credentials_with_provider_fails_closed_for_missing_named_credential():
router = litellm.Router(
model_list=[
{
"model_name": "embedding-model",
"litellm_params": {
"model": "azure/text-embedding-3-small",
"litellm_credential_name": "deleted-credential",
},
}
]
)
with patch.object(litellm, "credential_list", []):
credentials = router.get_deployment_credentials_with_provider(model_id="embedding-model")
assert credentials is None
def test_get_deployment_credentials_with_provider_preserves_project_id():
router = litellm.Router(
model_list=[
{
"model_name": "embedding-model",
"litellm_params": {
"model": "watsonx/ibm/slate-125m-english-rtrvr",
"api_key": "test-key",
"project_id": "embedding-project",
},
}
]
)
credentials = router.get_deployment_credentials_with_provider(model_id="embedding-model")
assert credentials is not None
assert credentials["project_id"] == "embedding-project"
def test_get_deployment_credentials_with_provider_bedrock_batch_fields():
"""
Test that get_deployment_credentials_with_provider returns the deployment's