diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index e4b8e6c8a..d5c09f651 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -97,6 +97,29 @@ def common_checks( raise Exception( f"'user' param not passed in. 'enforce_user_param'={general_settings['enforce_user_param']}" ) + if general_settings.get("enforced_params", None) is not None: + if route in LiteLLMRoutes.openai_routes.value: + # loop through each enforced param + # example enforced_params ['user', 'metadata', 'metadata.generation_name'] + for enforced_param in general_settings["enforced_params"]: + _enforced_params = enforced_param.split(".") + if len(_enforced_params) == 1: + if _enforced_params[0] not in request_body: + raise ValueError( + f"BadRequest please pass param={_enforced_params[0]} in request body. This is a required param" + ) + elif len(_enforced_params) == 2: + # this is a scenario where user requires request['metadata']['generation_name'] to exist + if _enforced_params[0] not in request_body: + raise ValueError( + f"BadRequest please pass param={_enforced_params[0]} in request body. This is a required param" + ) + if _enforced_params[1] not in request_body[_enforced_params[0]]: + raise ValueError( + f"BadRequest please pass param=[{_enforced_params[0]}][{_enforced_params[1]}] in request body. This is a required param" + ) + + pass # 7. [OPTIONAL] If 'litellm.max_budget' is set (>0), is proxy under budget if ( litellm.max_budget > 0