LLM Connection Issue: Azure GPT-4 Not Working on CrewAI Enterprise

Hi,
I am trying to run a Crew on CrewAI Enterprise, but the execution is failing with an error.

The Crew worked locally before being deployed via GitHub.

The LLM Connection was created and configured to use the Azure GPT-4o model (azure/gpt-4o).

I tested setting the environment variables in the project’s .env file, the deployment setup, and directly in CrewAI Enterprise’s environment variables, but none of these methods worked.

The error message is as follows:

Error Type:
AuthenticationError

Error Message:
litellm.AuthenticationError: AzureException AuthenticationError - Error code: 401 - {'statusCode': 401, 'message': 'Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired.'}

Does anyone know how to solve this?

Same issue, did you find the solution?

I had a 401 issue (not using Enterprise) that was solved by:

going to the Azure Portal and selecting the Azure OpenAi Resource where the LLM is deployed

Scroll down and click Explore Azure AI Foundry Portal

On the far left menu bar within the Foundry:

Scroll down to Shared Resources
and click on Deployments

this will bring up a list of your model deployments , if not then there is the first problem.

If you see your deployment in the list then click on it and a summary window will come up showing your Endpoint on the right top where you can double check the correct endpoint and key are in your .env file. To the left of this same window , if you scroll down , look for model version - THIS IS NOT the API version required to be in the .env file. I made this mistake.

To find the API version click the Button at the top that says Open in Playground and then click View Code. Scroll down and you will see

api_version="2024-05-01-preview",      #for example

my .env files uses the following:

AZURE_API_BASE=https://your-endpoint.openai.azure.com
AZURE_API_KEY=your-key
AZURE_API_VERSION=2024-05-01-preview

I am not using the endpoint in this form:
https://your-deployment.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-08-01-preview

Since the api-version is not correct…

Last tip is to try and login to azure at the command line where you are running crew, but for Enterprise I am not sure how you do this…

az login

I am really liking the Azure hookup to Crew (outside of Enterprise).
Hope this helps!

Thanks for your replay but the API version is not an issue, you can use 2024-05-01-preview, or 2024-08-01-preview or even 2024-02-15-preview. I tested my credentials with cURL and works with any API Version. The issue is somewhere else. CrewAI Enterprise actually give warning message instructions if you use wrong env key name, the keys should be: AZURE_DEPLOYMENT_TARGET_URL, AZURE_API_KEY and AZURE_API_VERSION, I only don’t understand the model choice and in Azure we name it freely, but I named my model as it is in select option.

I tested following cURL and it works with every above mentioned API version:
curl -X POST “https://.openai.azure.com/openai/deployments//chat/completions?api-version=2023-05-15”
-H “Content-Type: application/json”
-H “api-key: ”
-d ‘{
“messages”: [
{
“role”: “system”,
“content”: “You are a helpful assistant who helps to create and improve prompts to generate images.”
},
{
“role”: “user”,
“content”: “Create a prompt for image generation based on the following content: <image_prompt>. Return only the prompt, nothing else.”
}
],
“max_tokens”: 100,
“temperature”: 0.7,
“top_p”: 1.0
}’

I did some more digging

this was in one of the errors posted about this problem using Enterprise version.

I am showing that the correct URL might need to be:
microsoft.cognitiveservices.azure.com

I am guessing this setting is internal to the Enterprise version? If so you might have to open a support ticket from within that App.