API keys for OpenAI model deployments can't be obtained or generated programmatically via REST API. For security reasons, they must be manually created. After generation, these keys can then be incorporated into your code for accessing the API.
Hope this helps. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer
Thank You.