mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(proxy): validate enforced_file_expires_after keys before access
Add key validation for enforced_file_expires_after to return a clear 400 error instead of an unhandled KeyError 500.
This commit is contained in:
parent
08613b24cb
commit
d6ad312a4c
1 changed files with 11 additions and 0 deletions
|
|
@ -458,11 +458,22 @@ async def create_file( # noqa: PLR0915
|
|||
team_metadata = user_api_key_dict.team_metadata or {}
|
||||
enforced_file_expiry = team_metadata.get("enforced_file_expires_after")
|
||||
if enforced_file_expiry is not None:
|
||||
if "anchor" not in enforced_file_expiry or "seconds" not in enforced_file_expiry:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"error": "enforced_file_expires_after must contain 'anchor' and 'seconds' keys",
|
||||
},
|
||||
)
|
||||
expires_after = FileExpiresAfter(
|
||||
anchor=enforced_file_expiry["anchor"],
|
||||
seconds=enforced_file_expiry["seconds"],
|
||||
)
|
||||
|
||||
verbose_proxy_logger.info(
|
||||
"create_file expires_after: %s", expires_after
|
||||
)
|
||||
|
||||
_create_file_request = CreateFileRequest(
|
||||
file=file_data,
|
||||
purpose=cast(CREATE_FILE_REQUESTS_PURPOSE, purpose),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue