AI and LLM integration · Troubleshooting walkthrough
LangChain rejects AzureOpenAIEmbeddings before the first call
Short answer
1 validation error for AzureOpenAIEmbeddings means LangChain refused the endpoint settings before any request left your machine. The endpoint was given as openai_api_base or base_url, an old OPENAI_API_BASE variable sits next to azure_deployment, or no endpoint exists at all. Pass azure_endpoint or set AZURE_OPENAI_ENDPOINT, and unset OPENAI_API_BASE. Applies to langchain-openai 1.8.
"1 validation error for AzureOpenAIEmbeddings" is pydantic reporting that LangChain refused the endpoint settings before any request left your machine. The useful part is the Value error line underneath, because three different mistakes produce the same headline.
Read that line, then list the endpoint variables the process sees. The wording of the message points to the cause.
The text you see
1 validation error for AzureOpenAIEmbeddingsValue error, As of openai>=1.0.0, Azure endpoints should be specified via the `azure_endpoint` param not `openai_api_base` (or alias `base_url`).Value error, As of openai>=1.0.0, if `deployment` (or alias `azure_deployment`) is specified then `openai_api_base` (or alias `base_url`) should not be.Value error, Must provide one of the `base_url` or `azure_endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable
Stage 1
Match the Value error line to its cause
Endpoint variables in the environment (prints no key)
env | grep -E "^(OPENAI_API_BASE|OPENAI_BASE_URL|AZURE_OPENAI_ENDPOINT|OPENAI_API_VERSION)="| Wording in the Value error | Cause |
|---|---|
| Azure endpoints should be specified via the `azure_endpoint` param not `openai_api_base` | Endpoint passed under the old name |
| if `deployment` is specified then `openai_api_base` should not be | A stale OPENAI_API_BASE next to azure_deployment |
| Must provide one of the `base_url` or `azure_endpoint` arguments | No endpoint set anywhere |
Stage 2
Endpoint passed as openai_api_base or base_url
AzureOpenAIEmbeddings fails validation when openai_api_base (alias base_url) holds the resource URL and azure_endpoint is empty. Code written for versions of the openai library before 1.0 set the Azure address that way. In langchain-openai the validator turns it into a ValueError, and pydantic reports it as one validation error.
Move the address to azure_endpoint and name the deployment with azure_deployment. The key is read from AZURE_OPENAI_API_KEY when api_key is not passed.
Current constructor arguments
from langchain_openai import AzureOpenAIEmbeddings
embeddings = AzureOpenAIEmbeddings(
azure_deployment="text-embedding-3-small", # your deployment name
azure_endpoint="https://YOUR-RESOURCE-NAME.openai.azure.com/",
api_version="2025-04-01-preview",
)Stage 3
A forgotten OPENAI_API_BASE in .env
LangChain fills openai_api_base from the OPENAI_API_BASE environment variable when you do not pass it, so a value left in a .env file or shell profile from an older tutorial is picked up silently. With azure_deployment also set, the validator refuses the pair, even though your code passes only azure_endpoint.
Find it, then remove it from the shell and .env
grep -rn "OPENAI_API_BASE" .env* ~/.bashrc ~/.zshrc 2>/dev/null
unset OPENAI_API_BASE
sed -i.bak '/^OPENAI_API_BASE=/d' .envRestart the process afterwards so the old value is gone.
Stage 4
No endpoint anywhere
When neither azure_endpoint nor AZURE_OPENAI_ENDPOINT gives an address, the openai library's Azure client raises the "Must provide one of" message. LangChain builds that client inside its validator, so the error arrives wrapped as a validation error. A .env file that is never loaded leads here too.
Values from the Keys and Endpoint page of the Azure resource
export AZURE_OPENAI_ENDPOINT="https://YOUR-RESOURCE-NAME.openai.azure.com/"
export AZURE_OPENAI_API_KEY="<your key>"
export OPENAI_API_VERSION="2025-04-01-preview"Stage 5
Embed one word and count the vector
Creating the object should no longer raise, and embed_query returns a list of floats.
Smoke test
python -c "from app import embeddings; print(len(embeddings.embed_query('hello')))"- Pass
api_versionexplicitly or setOPENAI_API_VERSION; langchain-openai 1.8 reads that name and falls back to an older default when it is missing. - Keep only
AZURE_OPENAI_*variables in.envfor Azure projects. - If validation passes and the next failure is about a missing deployment, the deployment name is the problem, not the endpoint settings.
If you only keep one thing
- Use azure_endpoint, not openai_api_base or base_url.
- Delete a stale OPENAI_API_BASE.
- Set AZURE_OPENAI_ENDPOINT before the object is created.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.