Custom Azure OpenAI setup
You need to configure a non-default Azure OpenAI provider with a resource name and API key.
AI Tools · Function
createAzure creates a customized Azure OpenAI provider from settings such as an Azure resource name and API key. The provider can also use a complete Foundry OpenAI v1 base URL or Microsoft Entra ID token authentication.
createAzure constructs a customized Azure OpenAI provider from configuration such as the Azure resource name and API key. The returned provider is callable with a deployment name to obtain a model for AI SDK operations.
createAzure(options)| Name | Type | Description |
|---|---|---|
resourceName | string | Azure resource name used to construct the provider endpoint. |
apiKey | string | API key used for authentication. |
baseURL | string | Complete Microsoft Foundry OpenAI v1 endpoint; an alternative endpoint configuration. |
tokenProvider | () => Promise<string> | Token provider for Microsoft Entra ID authentication. |
A customized Azure OpenAI provider instance that can be called with a deployment name to obtain a model.
import { createAzure } from '@ai-sdk/azure';
const azure = createAzure({
resourceName: process.env.AZURE_RESOURCE_NAME!,
apiKey: process.env.AZURE_API_KEY!,
});
const model = azure('my-deployment');Creates a configured Azure OpenAI provider and selects a deployed model by deployment name.
You need to configure a non-default Azure OpenAI provider with a resource name and API key.
Your deployment uses a Microsoft Foundry OpenAI v1 endpoint.
Your application authenticates through Microsoft Entra ID instead of a static API key.
createAzure is imported from @ai-sdk/azure and returns a customized Azure OpenAI provider. The provider can then be called with a deployment name to select a model.
Follow-up: How would you authenticate without an API key? Pass a tokenProvider created with Microsoft Entra ID credentials, such as DefaultAzureCredential and getBearerTokenProvider.
The configuration can include resourceName and apiKey for a standard Azure resource. The resulting provider is invoked with the Azure deployment name, such as azure('my-deployment').
Follow-up: What alternative endpoint configuration is documented? Supply a complete Microsoft Foundry OpenAI v1 baseURL together with the required authentication configuration.
Use createAzure with a complete Microsoft Foundry OpenAI v1 baseURL when working with that endpoint style. The page shows a URL ending in /openai/v1 and an apiKey in the provider configuration.
Follow-up: What authentication alternative does the page document? Replace apiKey with a tokenProvider for Microsoft Entra ID authentication.
azure@ai-sdk/azuregenerateTexttokenProviderbaseURLresourceName