docs/adapters/nlp/azure.md
The Azure service provides integration with Azure OpenAI services, supporting both legacy API key authentication and modern Azure AD authentication. This integration enables Parlant to leverage Azure's enterprise-grade AI services while maintaining security best practices.
For local development, use Azure CLI authentication:
# Install Azure CLI if not already installed
# https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
# Login to Azure
az login
# Set your endpoint
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
For server deployment, do NOT use az login. Instead, use one of these methods:
# Set environment variables
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_CLIENT_ID="your-service-principal-client-id"
export AZURE_CLIENT_SECRET="your-service-principal-secret"
export AZURE_TENANT_ID="your-azure-tenant-id"
If running on Azure VMs, App Services, or other Azure resources:
# Only set the endpoint - authentication is automatic
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
For Kubernetes deployments:
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_CLIENT_ID="your-workload-identity-client-id"
export AZURE_TENANT_ID="your-azure-tenant-id"
export AZURE_FEDERATED_TOKEN_FILE="/var/run/secrets/azure/tokens/azure-identity-token"
AZURE_ENDPOINT: Your Azure OpenAI resource endpointAZURE_API_VERSION: API version (default: "2024-08-01-preview")AZURE_GENERATIVE_MODEL_NAME: Model name (default: "gpt-4o")AZURE_GENERATIVE_MODEL_WINDOW: Context window size (default: 4096)AZURE_EMBEDDING_MODEL_NAME: Embedding model (default: "text-embedding-3-large")AZURE_EMBEDDING_MODEL_DIMS: Embedding dimensions (default: 3072)AZURE_EMBEDDING_MODEL_WINDOW: Embedding context window (default: 8192)The Azure service supports any Azure OpenAI model that is deployed and available in your Azure OpenAI resource. The models listed below are pre-configured defaults, but you can use any model by setting the appropriate environment variables.
| Model Name | Description | Context Window | Use Case |
|---|---|---|---|
gpt-4o | Most capable GPT-4 model (default) | 128K tokens | Complex reasoning, high accuracy |
gpt-4o-mini | Faster, cost-effective GPT-4 | 128K tokens | Balanced performance and cost |
| Model Name | Dimensions | Context Window | Description |
|---|---|---|---|
text-embedding-3-large | 3072 | 8192 | High-quality embeddings (default) |
text-embedding-3-small | 3072 | 8192 | Efficient embeddings |
You can use any Azure OpenAI model that is deployed in your Azure OpenAI resource:
# Use any generative model (examples - check your Azure resource for availability)
export AZURE_GENERATIVE_MODEL_NAME="gpt-35-turbo" # GPT-3.5 Turbo
export AZURE_GENERATIVE_MODEL_NAME="gpt-4" # GPT-4
export AZURE_GENERATIVE_MODEL_NAME="gpt-4-turbo" # GPT-4 Turbo
# Use any embedding model (examples - check your Azure resource for availability)
export AZURE_EMBEDDING_MODEL_NAME="text-embedding-ada-002" # Ada embeddings
export AZURE_EMBEDDING_MODEL_NAME="text-embedding-3-large" # Large embeddings
Important:
The service follows this authentication priority:
For Azure AD authentication, ensure your identity has the following role on the Azure OpenAI resource:
import parlant.sdk as p
from parlant.sdk import NLPServices
async with p.Server(nlp_service=NLPServices.azure) as server:
agent = await server.create_agent(
name="Healthcare Agent",
description="Is empathetic and calming to the patient.",
)
Create Service Principal:
# Login as admin user
az login
# Create service principal
az ad sp create-for-rbac --name "parlant-service-principal" --role "Cognitive Services OpenAI User" --scopes "/subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP/providers/Microsoft.CognitiveServices/accounts/YOUR_OPENAI_RESOURCE"
Configure Environment Variables:
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_CLIENT_ID="appId-from-step-1"
export AZURE_CLIENT_SECRET="password-from-step-1"
export AZURE_TENANT_ID="tenant-from-step-1"
Test Authentication:
# Verify the service principal can access Azure OpenAI
python -c "
from parlant.adapters.nlp.azure_service import AzureService
error = AzureService.verify_environment()
print('Configuration OK' if error is None else f'Error: {error}')
"
export AZURE_ENDPOINT="https://my-resource.openai.azure.com/"
export AZURE_API_KEY="your-api-key"
export AZURE_GENERATIVE_MODEL_NAME="gpt-4o-mini"
export AZURE_ENDPOINT="https://my-resource.openai.azure.com/"
export AZURE_CLIENT_ID="your-client-id"
export AZURE_CLIENT_SECRET="your-client-secret"
export AZURE_TENANT_ID="your-tenant-id"
export AZURE_GENERATIVE_MODEL_NAME="gpt-4o"
Authentication Failures
Azure authentication is not properly configured.
Solution:
az login (only for local development)az login)Rate Limit Errors
Azure API rate limit exceeded
Solution:
Model Access Denied
Model not found or access denied
Solution:
Connection Errors
Cannot connect to Azure OpenAI endpoint
Solution:
AZURE_ENDPOINT is correctThe service provides these pre-configured model classes for convenience, but supports any Azure OpenAI model:
GPT_4o: Most capable GPT-4 model (128K context) - DefaultGPT_4o_Mini: Faster, cost-effective GPT-4 (128K context)AzureTextEmbedding3Large: High-quality embeddings (3072 dimensions) - DefaultAzureTextEmbedding3Small: Efficient embeddings (3072 dimensions)CustomAzureSchematicGenerator: Uses any generative model via AZURE_GENERATIVE_MODEL_NAMECustomAzureEmbedder: Uses any embedding model via AZURE_EMBEDDING_MODEL_NAMEThe service automatically chooses the appropriate class based on your environment variables.
The service uses this logic to select the appropriate model class:
# Generative Model Selection
if AZURE_GENERATIVE_MODEL_NAME is set:
use CustomAzureSchematicGenerator # Any model you specify
else:
use GPT_4o # Default model
# Embedding Model Selection
if AZURE_EMBEDDING_MODEL_NAME is set:
use CustomAzureEmbedder # Any embedding model you specify
else:
use AzureTextEmbedding3Large # Default embedding model
This means you can use any Azure OpenAI model without code changes - just set the environment variables!
# Use GPT-3.5 Turbo (if available in your region)
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_GENERATIVE_MODEL_NAME="gpt-35-turbo"
export AZURE_EMBEDDING_MODEL_NAME="text-embedding-ada-002"
# Use GPT-4 Turbo (if available in your region)
export AZURE_GENERATIVE_MODEL_NAME="gpt-4-turbo"
export AZURE_EMBEDDING_MODEL_NAME="text-embedding-3-large"
# Use default models (GPT-4o and text-embedding-3-large)
export AZURE_ENDPOINT="https://your-resource.openai.azure.com/"
# No need to set AZURE_GENERATIVE_MODEL_NAME or AZURE_EMBEDDING_MODEL_NAME
AzureService.verify_environment()The service maintains full backward compatibility: