Welcome to Microsoft Q&A Forum, thank you for posting your query here!
I understand that you are encountering an issue, The error message "Access denied due to invalid subscription key or wrong API endpoint" indicates that there may be an issue with the subscription key you are using or the API endpoint you are trying to access.
Above Error suggestions either endpoint url or key is malformed on invalid. Please make sure that your URL and endpoint is not containing any space or not malformed.
Kindly refer below Documentation: troubleshooting-steps
Thank You.