Failed to create thread: 401

I am trying to connect my azure ai foundary resources with my own template using python.

def create_thread():

"""Create a new conversation thread"""

url = f"{ENDPOINT}/threads?api-version={API_VERSION}"



headers = get_auth_headers()



response = requests.post(url, headers=headers, json={})

if response.status_code in \[200, 201\]:

    thread_data = response.json()

    return thread_data.get('id')

else:

    print(f"❌ Failed to create thread: {response.status_code} - {response.text}")

    return None

but I am frequently getting error as:

Failed to create thread: 401 - {“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.”}}

Can anyone help me with this?

Azure has a clever system where “they break it” → “you pay to help them fix it and restore their service.”

OpenAI is not Microsoft.