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]

fix(vector-stores): recurse into nested litellm_params; handle JSON-string shape

user294ac8383e39
diff --git a/litellm/proxy/vector_store_endpoints/management_endpoints.py b/litellm/proxy/vector_store_endpoints/management_endpoints.py
index 9a70ac8b762..48d08a35d7c 100644
--- a/litellm/proxy/vector_store_endpoints/management_endpoints.py
+++ b/litellm/proxy/vector_store_endpoints/management_endpoints.py
@@ -43,24 +43,41 @@ router = APIRouter()
_LITELLM_PARAMS_MASKER = SensitiveDataMasker()
-def _redact_sensitive_litellm_params(
- litellm_params: Optional[Dict[str, Any]],
-) -> Optional[Dict[str, Any]]:
+def _redact_sensitive_litellm_params(litellm_params: Any) -> Any:
"""
Replace credential-bearing values in ``litellm_params`` with
``REDACTED_BY_LITELM`` while preserving non-secret keys (``api_base``,
``region``, ``model``, ``api_version``).
+
+ Handles three input shapes:
+
+ * ``dict`` — recurse into nested dicts (e.g. ``litellm_embedding_config``
+ which itself carries ``api_key`` / ``aws_*`` / ``vertex_credentials``).
+ * ``str`` — the in-memory registry occasionally holds the params as a
+ JSON-serialized string. Parse, redact, re-serialize. If parsing
+ fails, return the redaction sentinel rather than echo the value
+ back verbatim.
+ * Anything else, or ``None`` — passed through.
"""
- if not litellm_params or not isinstance(litellm_params, dict):
+ if litellm_params is None:
+ return None
+ if isinstance(litellm_params, str):
+ try:
+ parsed = json.loads(litellm_params)
+ except (TypeError, ValueError):
+ return REDACTED_BY_LITELM_STRING
+ return json.dumps(_redact_sensitive_litellm_params(parsed))
+ if not isinstance(litellm_params, dict):
return litellm_params
- return {
- k: (
- REDACTED_BY_LITELM_STRING
- if _LITELLM_PARAMS_MASKER.is_sensitive_key(k)
- else v
- )
- for k, v in litellm_params.items()
- }
+ out: Dict[str, Any] = {}
+ for k, v in litellm_params.items():
+ if _LITELLM_PARAMS_MASKER.is_sensitive_key(k):
+ out[k] = REDACTED_BY_LITELM_STRING
+ elif isinstance(v, dict):
+ out[k] = _redact_sensitive_litellm_params(v)
+ else:
+ out[k] = v
+ return out
async def _fetch_and_authorize_vector_store(
diff --git a/tests/test_litellm/proxy/common_utils/test_openai_endpoint_utils.py b/tests/test_litellm/proxy/common_utils/test_openai_endpoint_utils.py
index 44288b027ae..3e3e89f8117 100644
--- a/tests/test_litellm/proxy/common_utils/test_openai_endpoint_utils.py
+++ b/tests/test_litellm/proxy/common_utils/test_openai_endpoint_utils.py
@@ -104,7 +104,9 @@ def test_remove_sensitive_info_from_deployment_with_excluded_keys():
assert sanitized_config["litellm_params"]["access_token"] != "token-12345"
assert "*" in sanitized_config["litellm_params"]["access_token"]
- # With excluded_keys, litellm_credentials_name should NOT be masked (even if it would match patterns)
+ # With excluded_keys, litellm_credentials_name should NOT be masked.
+ # ``remove_sensitive_info_from_deployment`` mutates its input, so feed it
+ # a fresh copy rather than the already-sanitized one.
sanitized_config = remove_sensitive_info_from_deployment(
copy.deepcopy(base_config), excluded_keys={"litellm_credentials_name"}
)
diff --git a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
index 92027e0a6f2..3d369ed2247 100644
--- a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
+++ b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
@@ -1951,6 +1951,78 @@ class TestRedactSensitiveLitellmParams:
_redact_sensitive_litellm_params(original)
assert original == snapshot, "input dict must not be mutated"
+ def test_redacts_nested_credentials_in_embedding_config(self):
+ """
+ ``/vector_store/new`` and ``/vector_store/update`` auto-resolve
+ ``litellm_embedding_config`` from the model registry and store it
+ as a nested dict inside ``litellm_params``. The nested dict carries
+ its own ``api_key`` / ``aws_*`` / ``vertex_credentials``, and a
+ non-recursive redactor would leak them.
+ """
+ from litellm.constants import REDACTED_BY_LITELM_STRING
+ from litellm.proxy.vector_store_endpoints.management_endpoints import (
+ _redact_sensitive_litellm_params,
+ )
+
+ params = {
+ "model": "openai/text-embedding-3-large",
+ "api_base": "https://api.openai.com/v1",
+ "litellm_embedding_config": {
+ "api_key": "sk-nested-secret",
+ "api_base": "https://nested.example.com",
+ "vertex_credentials": '{"private_key":"-----BEGIN..."}',
+ },
+ }
+ out = _redact_sensitive_litellm_params(params)
+ nested = out["litellm_embedding_config"]
+ assert nested["api_key"] == REDACTED_BY_LITELM_STRING
+ assert nested["vertex_credentials"] == REDACTED_BY_LITELM_STRING
+ assert nested["api_base"] == "https://nested.example.com"
+ # Top-level non-secrets preserved
+ assert out["api_base"] == "https://api.openai.com/v1"
+ assert out["model"] == "openai/text-embedding-3-large"
+
+ def test_redacts_json_string_litellm_params(self):
+ """
+ The in-memory registry occasionally holds ``litellm_params`` as a
+ JSON-serialized string rather than a dict. The redactor must parse,
+ redact, and re-serialize so callers don't get the raw string back.
+ """
+ import json as _json
+
+ from litellm.constants import REDACTED_BY_LITELM_STRING
+ from litellm.proxy.vector_store_endpoints.management_endpoints import (
+ _redact_sensitive_litellm_params,
+ )
+
+ params_json = _json.dumps(
+ {
+ "api_key": "sk-secret-from-json-string",
+ "api_base": "https://api.openai.com/v1",
+ }
+ )
+ out = _redact_sensitive_litellm_params(params_json)
+ assert isinstance(out, str)
+ parsed = _json.loads(out)
+ assert parsed["api_key"] == REDACTED_BY_LITELM_STRING
+ assert parsed["api_base"] == "https://api.openai.com/v1"
+
+ def test_redacts_unparseable_string_litellm_params(self):
+ """
+ If ``litellm_params`` is a string that isn't valid JSON, the
+ redactor must NOT echo the value back verbatim — it could contain
+ opaque credential material.
+ """
+ from litellm.constants import REDACTED_BY_LITELM_STRING
+ from litellm.proxy.vector_store_endpoints.management_endpoints import (
+ _redact_sensitive_litellm_params,
+ )
+
+ out = _redact_sensitive_litellm_params(
+ "this is not json but might contain a secret"
+ )
+ assert out == REDACTED_BY_LITELM_STRING
+
class TestUpdateVectorStoreAccessControlAndRedaction:
"""