The 504 Gateway Timeout error typically indicates that a server did not receive a timely response. In this case, it's possible that the operation of granting permissions to a large number of recipients is taking longer than the server's wait time, hence the timeout error.
As a workaround, you could try to split the operation into smaller batches and add some delay between each batch to avoid hitting the rate limit.
Thanks,
Prasad Das
*************************************************************************
If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.