Skip to content

Commit c09d9e5

Browse files
ishaan-jaffcursoragentishaan-berri
authored
feat: Validate LiteLLM Virtual Key format (#14428)
Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: ishaan <[email protected]>
1 parent 1f42e41 commit c09d9e5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

litellm/proxy/management_endpoints/key_management_endpoints.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,15 @@ async def _common_key_generation_helper( # noqa: PLR0915
551551
prisma_client=prisma_client,
552552
)
553553

554+
# Validate user-provided key format
555+
if data.key is not None and not data.key.startswith("sk-"):
556+
raise HTTPException(
557+
status_code=400,
558+
detail={
559+
"error": f"Invalid key format. LiteLLM Virtual Key must start with 'sk-'. Received: {data.key}"
560+
}
561+
)
562+
554563
response = await generate_key_helper_fn(
555564
request_type="key", **data_json, table_name="key"
556565
)

0 commit comments

Comments
 (0)