I’m trying to use the OpenAI Agents framework on Python, but using Azure Open AI for model inference
I keep getting this annoying error printed to my console, any way to suppress it?
[non-fatal] Tracing client error 401: {
"error": {
"message": "Incorrect API key provided: <missing*****key>. You can find your API key at https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}
e.g.
def create_openai_client() -> AsyncAzureOpenAI:
"""
Function to create an OpenAI client.
This is a placeholder function and should be replaced with actual implementation.
"""
credential = DefaultAzureCredential()
return AsyncAzureOpenAI(
azure_endpoint="https://aoai-resource.openai.azure.com/",
azure_deployment="gpt-4o",
azure_ad_token_provider=lambda: credential.get_token("https://cognitiveservices.azure.com/.default").token,
api_version="2025-03-01-preview"
)
async def main():
openai_client = create_openai_client()
set_default_openai_client(openai_client)
# Create a banking assistant agent
banking_assistant = Agent(
name="Banking Assistant",
instructions="You are a helpful banking assistant. Be concise and professional.",
model=OpenAIChatCompletionsModel(
model="gpt-4o",
openai_client=openai_client
),
tools=[check_account_balance] # A function tool defined elsewhere
)