Access denied due to invalid subscription key or wrong API endpoint

Zili Yang 5 Reputation points
2024-01-06T17:34:57.0866667+00:00

Hi, I just created a new subscription to Bing Web search API under S6 Pricing tier, and I tried the new key and search_url ("https://api.bing.microsoft.com/v7.0/search"). However, the results returned

{"error":{"code":"401","message":"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."}}


But it just worked for my free pricing tier. I just changed keys and nothing else.

BTW, I am using Python to call the search.

Thanks for your help!

Bing Web Search
Bing Web Search
A Bing service that gives you enhanced search details from billions of web documents.
128 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 17,120 Reputation points Microsoft Employee
    2024-01-08T09:24:37.3266667+00:00

    @Zili Yang 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 -H "Ocp-Apim-Subscription-Key: <yourkeygoeshere>" https://api.bing.microsoft.com/v7.0/search?q=microsoft+devices
    

    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.