feat: Validate LiteLLM Virtual Key format (#14428)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: ishaan <ishaan@berri.ai>
This commit is contained in:
Ishaan Jaff
2025-09-10 18:58:48 -07:00
committed by GitHub
parent 1f42e41c8d
commit c09d9e5e8e
@@ -551,6 +551,15 @@ async def _common_key_generation_helper( # noqa: PLR0915
prisma_client=prisma_client,
)
# Validate user-provided key format
if data.key is not None and not data.key.startswith("sk-"):
raise HTTPException(
status_code=400,
detail={
"error": f"Invalid key format. LiteLLM Virtual Key must start with 'sk-'. Received: {data.key}"
}
)
response = await generate_key_helper_fn(
request_type="key", **data_json, table_name="key"
)