When I connected Azure, I remember is being a massive pain because they gave me three different API keys and a different endpoint URLs.
Just to ensure the details are correct, could you confirm your connection is working outside of Cursor, with the same API details?
You should be able to get an answer running the juypter notebook below (just ensure you replace variables or have them set in your .env file):
import os
from openai import AzureOpenAI
from typing import Dict, Union
from dotenv import load_dotenv
# Load environment variables
load_dotenv(override=True)
endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT_ID", "gpt-4o")
subscription_key = os.getenv("AZURE_OPENAI_API_KEY")
api_version=os.getenv("AZURE_OPENAI_API_VERSION", "2024-05-01-preview")
def test_azure_openai(prompt: str = "What is the capital of France?") -> Dict[str, Union[str, None]]:
"""
Test Azure OpenAI connectivity using a deployed model.
:param prompt: Input question to test the model
:type prompt: str
:return: Dictionary containing response or error message
:rtype: Dict[str, Union[str, None]]
"""
try:
client = AzureOpenAI(
api_key=subscription_key,
api_version=api_version,
azure_endpoint=endpoint,
)
# Get the exact deployment name
deployment_name = os.getenv("AZURE_OPENAI_DEPLOYMENT_ID", "gpt-4o") # Ensure this is correct
print(deployment_name)
# Print the inputs
print(f"Deployment Name: {deployment_name}")
print(f"Prompt: {prompt}")
response = client.chat.completions.create(
model=deployment_name, # Use the exact deployment name
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
max_tokens=100,
)
return {"response": response.choices[0].message.content, "error": None}
except Exception as e:
return {"response": None, "error": str(e)}
# Run it
if __name__ == "__main__":
result = test_azure_openai()
if result["error"]:
print(f"Error: {result['error']}")
else:
print(f"Response: {result['response']}")
Note in this case I assumed the deployment_name was gpt-4o.
Thanks for the code snippets! I’ve made some attempts on this code, and it seems to be an issue on Azure side.
The original model I was trying to run with was DeepSeek-R1, which when run with this script, returned an error 400 - {'error': {'code': 'unknown_model', 'message': 'Unknown model: ds-r1', 'details': 'Unknown model: ds-r1'}}. It seems to be a similar error cursor got.
I tried the script with anPhi-4 model deployment but the error became 500 - {'error': {'code': 'InternalServerError', 'message': 'Backend returned unexpected response. Please contact Microsoft for help.'}}. It was clearly an Azure issue.
It was finally working with an o1-mini deployment, but the temperature and max_token parameters must be removed for this deployment.
It seems not all models in Azure AI are working fine with cursor.