feat(v2 managed agents): add litellm_api_key masking helper

This commit is contained in:
Ishaan Jaffer 2026-05-07 10:06:55 -07:00
parent 41c484ed97
commit 6a618c51d3
No known key found for this signature in database

View file

@ -0,0 +1,19 @@
"""Masking helpers for managed agents.
The agent's `litellm_api_key` is stored encrypted-at-rest by the proxy and
returned masked on every read `sk-abc123def456` `sk-a****`.
"""
def mask_litellm_api_key(key: str) -> str:
"""Return a masked form of a LiteLLM API key.
Pattern: keep the first 4 characters of the key (including any
`sk-`-style prefix), then append `****`. For very short keys, mask
everything to avoid leaking too much.
"""
if not key:
return ""
if len(key) <= 4:
return "****"
return f"{key[:4]}****"