An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
Hi Yi Chun Lam
agent_framework.exceptions.ServiceInitializationError: Azure credential is required when agents_client is not provided. happens when the client cannot find a usable Azure credential object (it’s None / not passed / not valid), and you didn’t pass a pre-built agents_client.
So the SDK has no way to authenticate to Azure AI Agents / Azure AI Project. [agent_fram...soft Learn | Learn.Microsoft.com], [azure.ai.a...soft Learn | Learn.Microsoft.com], [agent_fram...soft Learn | Learn.Microsoft.com]
In most lab environments, your code creates a credential like DefaultAzureCredential() or AzureCliCredential(), but you are not logged in (or the credential chain can’t find any valid auth method). Then the SDK effectively behaves like “no credential provided”, triggering this error. The official quickstart explicitly calls out using Azure CLI auth (az login) and having access to the Azure AI project. [Microsoft...soft Learn | Learn.Microsoft.com], [Create and...soft Learn | Learn.Microsoft.com]
3) Fix #1 (recommended for labs): use Azure CLI credential and ensure you’re logged in
Step A — Login
Run this in your terminal:
Shell
az login
az account show
This ensures the CLI token exists for AzureCliCredential() to use. [Microsoft...soft Learn | Learn.Microsoft.com], [Create and...soft Learn | Learn.Microsoft.com]
4)Step B — Use the credential correctly in code
The AzureAIAgentClient expects a credential= parameter (per the SDK docs). If you pass async_credential= to AzureAIAgentClient, it may not bind to the right parameter and the SDK will treat it like no credential was provided. Use credential=... like below. [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]
import asyncio
from azure.identity.aio import AzureCliCredential
from agent_framework.azure import AzureAIAgentClient
async def main():
async with AzureCliCredential() as credential:
async with AzureAIAgentClient(credential=credential) as client:
# run your agent calls here
pass
if __name__ == "__main__":
asyncio.run(main())
This matches the documented constructor usage for AzureAIAgentClient(... credential= ...). [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]
- Fix #2: Make sure required environment variables are set (very common missing step)
Even with a valid credential, the SDK also needs to know where your Azure AI project is and which model deployment to use.
Set these (either in your shell or in a .env file):
-
AZURE_AI_PROJECT_ENDPOINT -
AZURE_AI_MODEL_DEPLOYMENT_NAME
The SDK docs and quickstart show these exact variables. [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]
Example:
Shell
export AZURE_AI_PROJECT_ENDPOINT="https://<your-project>.cognitiveservices.azure.com"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini"
Or load from .env:
Python
client = AzureAIAgentClient(credential=credential, env_file_path=".env")
[agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]
Fix #3: If you really intended to pass a pre-built AgentsClient
The error message says “credential is required when agents_client is not provided”. That means alternative path is: create an AgentsClient(endpoint, credential) yourself and pass it in as agents_client=.... The AgentsClient constructor requires both endpoint and credential. [azure.ai.a...soft Learn | Learn.Microsoft.com]
Conceptually:
Python
from azure.ai.agents.aio import AgentsClient
from azure.identity.aio import AzureCliCredential
from agent_framework.azure import AzureAIAgentClient
agents = AgentsClient(endpoint=PROJECT_ENDPOINT, credential=credential)
client = AzureAIAgentClient(agents_client=agents, credential=credential)
(Exact import path may differ by version, but the key is: AgentsClient requires endpoint + credential.) [agent_fram...soft Learn | Learn.Microsoft.com]
6) Quick checklist (this resolves 95% of cases)
-
pip show agent-framework agent-framework-azure-ai azure-identity(packages installed) -
az logincompleted successfully - You used
AzureCliCredential()or a workingDefaultAzureCredential() - You passed it as
credential=credentialintoAzureAIAgentClient -
AZURE_AI_PROJECT_ENDPOINT+AZURE_AI_MODEL_DEPLOYMENT_NAMEare set
These align directly with the SDK constructor + quickstart requirements. [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com], [Create and...soft Learn | Learn.Microsoft.com]
Please let me know and if there are any remaining questions or additional details, I can help with, I’ll be glad to provide further clarification or guidance.
Thankyou!