Your code is correct. You need to assign an RBAC role to your authenticated user against an AI Foundry project. It has to be Cognitive Services Contributor or Cognitive Services OpenAI Contributor.