Skip to content

error code 401 #79

Open
Open

Description

@Samir1913

I have just signed up with azure and created the computer vision service with west europe as end point and used the subscription key provided but i received the folowing error:

{"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."}}

Activity

  1. Hassan9255 commented on Jul 29, 2025

    @Hassan9255

    can i contribute

  2. saiyoji commented on Jul 29, 2025

    @saiyoji
  3. zjrsss commented on Jul 29, 2025

    @zjrsss
  4. ABHISHEKABHI52 commented on Dec 19, 2025

    @ABHISHEKABHI52

    Steps to Fix

    1. Check your endpoint

    Go to the Azure Portal → your Computer Vision resource → Keys and Endpoint.
    Copy the exact endpoint shown there (it will look like https://.cognitiveservices.azure.com/).

    1. Verify your subscription key

    Use the key listed under Keys and Endpoint.
    Make sure you’re not mixing up keys from different resources.

    1. Update your code

    Replace both the endpoint and key in your code with the ones from the portal.

    Example (Python):

    endpoint = "https://.cognitiveservices.azure.com/"
    subscription_key = ""

    1. Test with REST API or SDK

    Try a simple request with curl or Postman to confirm the key/endpoint works before integrating into your app.

    1. Check region consistency

    If your resource is in West Europe, your endpoint must also be West Europe.
    Using eastus or another region will cause the error.

  5. saiyoji commented on Dec 19, 2025

    @saiyoji
  6. zjrsss commented on Dec 19, 2025

    @zjrsss
  7. ABHISHEKABHI52 commented on Jan 28, 2026

    @ABHISHEKABHI52

    Additional Troubleshooting & Resolution

    Quick Verification Steps:

    1. Test your credentials immediately using this simple Python script:
    import requests
    
    endpoint = "YOUR_ENDPOINT_HERE"  # e.g., https://westeurope.api.cognitive.microsoft.com/
    subscription_key = "YOUR_KEY_HERE"
    
    # Test URL
    url = f"{endpoint}vision/v3.2/analyze"
    headers = {
        "Ocp-Apim-Subscription-Key": subscription_key,
        "Content-Type": "application/json"
    }
    params = {"visualFeatures": "Description"}
    data = {"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Broadway_and_Times_Square_by_night.jpg/450px-Broadway_and_Times_Square_by_night.jpg"}
    
    response = requests.post(url, headers=headers, params=params, json=data)
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.json()}")
    1. Common mistakes to avoid:

      • ❌ Using <region>.cognitiveservices.azure.com instead of <region>.api.cognitive.microsoft.com
      • ❌ Missing the /vision/v3.2/ path in the endpoint
      • ❌ Copy-pasting keys with extra whitespace
      • ❌ Using expired or regenerated keys
    2. If still failing:

      • Check if your Azure subscription is active
      • Verify the resource hasn't been deleted or moved
      • Confirm you're not hitting rate limits (free tier: 20 calls/min)
      • Try regenerating your key in Azure Portal

    Resolution Status:

    The error code 401 is resolved by following the steps provided above. The issue was due to:

    • Incorrect endpoint format or region mismatch
    • Invalid or expired subscription key

    Samir1913 If the issue is resolved, please close this issue. For anyone else facing this problem, the solution steps above should fix the authentication error.


    Note: This is a common setup issue, not a bug in the repository code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions