Azure AI embeddings model using the OpenAI-compatible API.
Azure AI embeddings model using the OpenAI-compatible API.
This class wraps :class:langchain_openai.OpenAIEmbeddings and adds
support for the project-endpoint pattern available in Azure AI Foundry,
in addition to the classic endpoint + API-key style used by Azure OpenAI.
Use AzureAIOpenAIApiEmbeddingsModel with any Foundry model compatible with
OpenAI APIs (e.g. gpt-5, Mistral, Cohere.) to get the benefits of
unified authentication, single configuration, and seamless integration
with other Azure services.
Project-endpoint pattern (recommended for Azure AI Foundry):
from langchain_azure_ai.embeddings import AzureAIOpenAIApiEmbeddingsModel
from azure.identity import DefaultAzureCredential
embed_model = AzureAIOpenAIApiEmbeddingsModel(
project_endpoint=(
"https://resource.services.ai.azure.com/api/projects/my-project"
),
credential=DefaultAzureCredential(),
model="text-embedding-3-small",
)
Parameter model refers to the model deployment name in Azure AI Foundry,
which may differ from the base model name depending on how the deployment
was configured.
If project_endpoint is omitted the value of the
AZURE_AI_PROJECT_ENDPOINT environment variable is used.
Direct endpoint + API-key pattern:
from langchain_azure_ai.embeddings import AzureAIEmbeddingsModel
embed_model = AzureAIOpenAIApiEmbeddingsModel(
endpoint="https://resource.services.ai.azure.com/openai/v1",
credential="your-api-key",
model="text-embedding-3-small",
api_version="2024-05-01-preview",
)
Environment variables:
The following environment variables are recognised as fallbacks when the corresponding constructor parameters are not provided:
AZURE_AI_PROJECT_ENDPOINT ā used as project_endpoint.AZURE_AI_OPENAI_ENDPOINT ā direct OpenAI-compatible endpoint
(e.g. https://<resource>.services.ai.azure.com/openai/v1).
Used as endpoint verbatim (no path is appended).AZURE_OPENAI_ENDPOINT ā root Azure OpenAI endpoint (e.g.
https://<resource>.services.ai.azure.com). /openai/v1 is
appended automatically and the result is treated as endpoint.AZURE_OPENAI_DEPLOYMENT_NAME ā model deployment name (model).AZURE_OPENAI_API_VERSION ā API version passed as the
api-version query parameter on every request.Resolution priority (highest ā lowest):
AZURE_AI_PROJECT_ENDPOINT environment variable.AZURE_AI_OPENAI_ENDPOINT environment variable.AZURE_OPENAI_ENDPOINT / AZURE_OPENAI_API_VERSION /
AZURE_OPENAI_DEPLOYMENT_NAME environment variables.AZURE_AI_PROJECT_ENDPOINT, AZURE_AI_OPENAI_ENDPOINT, and
AZURE_OPENAI_ENDPOINT may all be set at the same time; the project
endpoint takes precedence, then AZURE_AI_OPENAI_ENDPOINT, then
AZURE_OPENAI_ENDPOINT. However, passing both project_endpoint
and endpoint as constructor parameters raises :class:ValueError.
All other keyword arguments accepted by
:class:langchain_openai.AzureOpenAIEmbeddings are forwarded as-is.