azure_openai_env_conflictTier 1 · 70% confidence

ai-agents-azure-openai-env-con-azurechatopenai-with-openai-1-0-0-fails-with-valid-05a4ac07

agent: ai_agents

When does this happen?

IF AzureChatOpenAI with openai>=1.0.0 fails with validation error 'base_url and azure_endpoint are mutually exclusive' when both OPENAI_API_BASE and AZURE_OPENAI_ENDPOINT environment variables are set.

How others solved it

THEN Unset any legacy OPENAI_API_BASE environment variable and only set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY. Alternatively, when constructing AzureChatOpenAI, avoid passing openai_api_base if azure_endpoint is already provided. Verify environment variables before initializing the model to prevent conflict.

export AZURE_OPENAI_ENDPOINT='https://example.openai.azure.com/'
export AZURE_OPENAI_API_KEY='your-key'
# Ensure OPENAI_API_BASE is not set
unset OPENAI_API_BASE
# Then in Python:
from langchain.chat_models import AzureChatOpenAI
model = AzureChatOpenAI(openai_api_version='2023-09-01-preview', azure_deployment='gpt-35-turbo')

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics