Hi @fr.sxtyxm and @muskanrxl89
In the following tutorial the process for setting up the API key for use in image generation is shown in detail again. For me it worked to just follow the steps mentioned there. Maybe this will help you two as well? If you are using this in a different use case you could build this in PowerApps and then view the raw code to compare it to yours.
Creating a PowerApps custom connector for Dall-e image generation using OpenAI and Postman - YouTube
You can refer to the following Video for Setup for text based models: ChatGPT Custom Connector for Power Platform | How to use Chat GPT API in Power Apps & Automate - YouTube