How do I connect to Azure AI endpoint properly (401 errors)

SHERMAN BOYD 0 Reputation points
2025-01-14T22:39:32.4833333+00:00

I set up an AI inference endpoint following the instructions:

User's image

I've tried different variations of the target url, and destroyed and recreated the deployments. I tried gpt-4o and gpt-4o-mini as well. But whatever I try I get a 401 error when I attempt to connect to it using a REST client. Can anyone provide an example of an URL that works with an AI inference endpoint? Or a Postman collection that works?

I'm running on an Azure trial account, could that be the issue?

 curl -X POST https://sherm-m5x0h0o0-swedencentral.openai.azure.com/openai/deployments/gpt-35-turbo-instruct/chat/completions?api-version=2024-08-01-preview -H "Authorization: Bearer redacted-token-goes here" -H "Content-Type: application/json" -d '{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Explain Riemanns conjecture in 1 paragraph."}],"max_tokens":150}' { "statusCode": 401, "message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired." }

Tried recreating the tokens too.

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,283 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vikram Singh 2,550 Reputation points Microsoft Employee
    2025-01-15T07:48:27.48+00:00

    Hello @SHERMAN BOYD , Greetings!

    Thanks for posting your question in Microsoft Q&A, apologize for any inconvenience caused on this.

    A 401 Unauthorized error typically points to issues with your access token. Here are common causes and solutions:

    • Invalid or Missing Token: Ensure your access token is correctly generated and included in the Authorization header.
    • Incorrect Audience: Verify the token's audience is set to https://cognitiveservices.azure.com.
    • Trial Account Limitations: Trial accounts may have restrictions on available models and usage quotas. Check Azure AI Usage Limitations for more details.
    • Postman Collection: Use a Postman collection for testing to ensure correct headers and payload structure. Example collections for Azure AI are available in the documentation.

    For trial accounts, consider using the free tier (SKU: F0) to explore the service. Review pricing options here: Azure Cognitive Services Pricing.

    Additional Tip: Try using a freshly generated access token to resolve potential token issues.

    Do let me know if you are still the facing the issue.


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.