We are trying to create an Agent that connects to Azure Open AI using the below code. We do not have Open API Key and are asked to use Azure AD token. this works fine when we are validating the LLM . However the crew agents are not able to use the LLM.
credential = AzureCliCredential()
token = credential.get_token(“”)
scope = “https://cognitiveservices.azure.com/.default”
endpoint = “”
apiVersion = “2025-01-01-preview”
deployment = “”
llm = AzureChatOpenAI(
azure_endpoint=endpoint,
api_version=apiVersion,
deployment_name=deployment,
azure_ad_token_provider=lambda: AzureCliCredential().get_token(scope).token,
temperature=0.7,
max_tokens=100,
)
agent = Agent(
role=“Senior Researcher”,
goal=“Uncover groundbreaking technologies in AI”,
backstory=“Driven by curiosity, you explore and share knowledge that could change the world.”,
verbose=True,
llm=llm,
allow_delegation=False # Prevent delegation errors
)
When runnign the crew we are getting the error
Crew: crew
└── Task: cf890b03-4dc6-40f7-aab0-220a96282852
Assigned to: Senior Researcher
Status: Failed
└── LLM Failed
raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable