Skip to main content
The azure-openai provider supports the Azure OpenAI /chat/completions endpoint.
If you’re using the new Microsoft Foundry portal, use the microsoft-foundry provider instead.

Quick Start

client<llm> MyClient {
  provider "azure-openai"
  options {
    resource_name "my-resource-name"
    deployment_id "my-deployment-id"
    api_version "2024-02-01"
    api_key env.AZURE_OPENAI_API_KEY
  }
}
api_version is required. Azure will return “not found” if the version is not specified.

Authentication

Set your Azure OpenAI API key as an environment variable:
export AZURE_OPENAI_API_KEY="your-api-key-here"
Or specify it explicitly in your BAML configuration:
client<llm> MyClient {
  provider "azure-openai"
  options {
    resource_name "my-resource-name"
    deployment_id "my-deployment-id"
    api_version "2024-02-01"
    api_key env.MY_AZURE_KEY
  }
}

Configuration Options

BAML-Specific Options

These options modify the API request sent to Azure OpenAI.
api_key
string
default:"env.AZURE_OPENAI_API_KEY"
Injected via the API-KEY header.
resource_name
string
required
Your Azure OpenAI resource name. Used to construct the base URL.The base URL is constructed as:
https://${resource_name}.openai.azure.com/openai/deployments/${deployment_id}
deployment_id
string
required
Your Azure OpenAI deployment ID. This is the name you gave your model deployment in the Azure portal.
api_version
string
required
The Azure OpenAI API version. Passed as a query parameter api-version.Common versions:
  • 2024-02-01
  • 2023-12-01-preview
See Azure API versioning for available versions.
base_url
string
Alternative to resource_name and deployment_id. Specify the full base URL directly:
client<llm> MyClient {
  provider "azure-openai"
  options {
    base_url "https://my-resource-name.openai.azure.com/openai/deployments/my-deployment-id"
    api_version "2024-02-01"
    api_key env.AZURE_OPENAI_API_KEY
  }
}
headers
object
Additional headers to send with requests.
client<llm> MyClient {
  provider "azure-openai"
  options {
    resource_name "my-resource-name"
    deployment_id "my-deployment-id"
    api_version "2024-02-01"
    api_key env.AZURE_OPENAI_API_KEY
    headers {
      "X-My-Header" "my-value"
    }
  }
}

Model Parameters

These parameters are passed directly to the Azure OpenAI API.
For reasoning models like o1 or o1-mini, use max_completion_tokens instead of max_tokens. Set max_tokens to null.See the OpenAI API documentation for details.
client<llm> AzureO1 {
  provider "azure-openai"
  options {
    resource_name "my-resource"
    deployment_id "o1-mini"
    api_version "2024-02-01"
    max_tokens null
    max_completion_tokens 4096
  }
}
Common parameters:
  • temperature - Controls randomness (0-2)
  • max_tokens - Maximum tokens to generate
  • top_p - Nucleus sampling parameter
  • frequency_penalty - Reduces repetition (-2.0 to 2.0)
  • presence_penalty - Encourages new topics (-2.0 to 2.0)
For all options, see the Azure OpenAI API documentation.

Finding Your Configuration

In the Azure Portal:
  1. Go to your Azure OpenAI resource
  2. Navigate to “Keys and Endpoint”
  3. Find:
    • Resource name: In the endpoint URL (e.g., https://YOUR-RESOURCE.openai.azure.com/)
    • API key: Under “Key 1” or “Key 2”
  4. Navigate to “Model deployments” to find your deployment_id

Features

  • Streaming: Supported for real-time response generation
  • Multimodal: Support depends on your deployed model
  • Azure Integration: Works with Azure AD authentication and private endpoints
  • Regional Deployment: Deploy in your preferred Azure region

Do Not Set

messages
DO NOT USE
BAML automatically constructs this from your prompt.
stream
DO NOT USE
BAML automatically sets this based on how you call the client in your code.

Build docs developers (and LLMs) love