Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

createAzure

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.

How it works

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.

Syntax

createAzure(options)

Parameters

NameTypeDescription
resourceNamestringAzure resource name used to construct the provider endpoint.
apiKeystringAPI key used for authentication.
baseURLstringComplete Microsoft Foundry OpenAI v1 endpoint; an alternative endpoint configuration.
tokenProvider() => Promise<string>Token provider for Microsoft Entra ID authentication.

Returns

A customized Azure OpenAI provider instance that can be called with a deployment name to obtain a model.

Key points

  • Import createAzure from the @ai-sdk/azure package.
  • Use createAzure when the default provider instance does not provide the configuration you need.
  • resourceName identifies the Azure resource used by the provider.
  • apiKey is one documented way to authenticate the provider.
  • The function returns a provider instance that can be assigned to a local variable.
  • A complete Foundry OpenAI v1 endpoint can be supplied through baseURL.

Common mistakes

  • When targeting Microsoft Foundry OpenAI v1, configure the complete base URL instead of relying only on resourceName.
  • Entra ID authentication uses a tokenProvider rather than an API key; the documentation shows obtaining one with Azure Identity helpers.

Example: Create an Azure OpenAI provider

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.

When to use it

Custom Azure OpenAI setup

You need to configure a non-default Azure OpenAI provider with a resource name and API key.

Foundry v1 endpoint configuration

Your deployment uses a Microsoft Foundry OpenAI v1 endpoint.

Token-based authentication

Your application authenticates through Microsoft Entra ID instead of a static API key.

Interview questions

QWhat does createAzure create, and how is its result used?

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.

QHow do you configure createAzure for a regular Azure OpenAI resource?

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.

QWhen would baseURL be used instead of resourceName?

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/azure
  • generateText
  • tokenProvider
  • baseURL
  • resourceName

Source: Azure OpenAI Provider - AI SDK. Checked 2026-10-15.