Access denied due to invalid subscription key or wrong API endpoint.

HHjAh 0 Reputation points
2023-05-03T12:35:02.1933333+00:00

Hey,

Trying to make an call to the bing image search.

curl "https://api.bing.microsoft.com/v7.0/images/search?Ocp-Apim-Subscription-Key=SECRET_KEY&q=microsoft"

But getting the following error:

Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

Not sure what I'm doing wrong as I've grabbed the key from the key1 input.

Screenshot 2023-05-03 at 14.33.44

Bing Image Search
Bing Image Search
A Bing service that supports searching for images and gets comprehensive results.
49 questions
{count} votes

2 answers

Sort by: Most helpful
  1. VasaviLankipalle-MSFT 18,296 Reputation points
    2023-05-03T23:57:34.3766667+00:00

    Hi @HHjAh , Thanks for using Microsoft Q&A Platform.

    Please make sure you are using correct subscription key or API endpoint.

    I have reproduced this everything works well on my end. Here's the CURL command again for your reference please try this:

    curl "https://api.bing.microsoft.com/v7.0/images/search?q=microsoft" -H "Ocp-Apim-Subscription-Key: YOUR_SECRET_KEY"
    

    Replace YOUR_SECRET_KEY with your actual subscription key. If the issue still persists, I would recommend regenerating your subscription key in the Azure portal and try again.

    I hope this helps.

    Regards,
    Vasavi

    -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks.

    2 people found this answer helpful.

  2. Vishal Bondwal 0 Reputation points
    2024-08-01T03:15:20.28+00:00

    We were getting the same error in Azure AI. Turns out that some services are automatically created in another region if they are not available in your region. Our entire Azure workloads are in Australia, but when we created the document intelligence service, it silently got created in East US.

    So when you see the Endpoints & Keys section of your dashboard, it will show where you created it (or where the subscription is, in our case both are the same, Australia), but the actual AI service is running from East US. The only place where we could see this contrasting location was in Cost Management > Cost Analysis > Resources.

    location list

    It could possibly be because AI services are not rolled out worldwide, so there is a higher probability of they ending up in a different region than where the keys and endpoint are defined. We created a new resource in East US, and used the keys and endpoint from there, and it started working without any problem.

    Also make sure that the key for the API Key is named Ocp-Apim-Subscription-Key, and not apiKey or api-key.

    Couldn't find clear/accessible documentation on the above, but it finally works.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.