diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 367ea4478c..88f0fe69fb 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -1155,8 +1155,9 @@ async def update_ldap_config(request: Request, form_data: LdapConfigForm, user=D # create api key @router.post('/api_key', response_model=ApiKey) async def generate_api_key(request: Request, user=Depends(get_current_user), db: Session = Depends(get_session)): - if not request.app.state.config.ENABLE_API_KEYS or not has_permission( - user.id, 'features.api_keys', request.app.state.config.USER_PERMISSIONS + if not request.app.state.config.ENABLE_API_KEYS or ( + user.role != 'admin' + and not has_permission(user.id, 'features.api_keys', request.app.state.config.USER_PERMISSIONS) ): raise HTTPException( status_code=status.HTTP_403_FORBIDDEN,