# How to Configure Azure OpenAI as the LLM Provider in DAT

> Easily configure Azure OpenAI as your LLM provider in DAT. Follow our clear steps to add the Maven dependency, declare your model in project.yaml, and provide the necessary Azure OpenAI parameters.

- Repository: [Junjie.M/dat](https://github.com/junjiem/dat)
- Tags: how-to-guide
- Published: 2026-03-05

---

**To configure Azure OpenAI in DAT, add the `dat-llm-azure-openai` Maven dependency, declare a model with `provider: azure-openai` in your [`project.yaml`](https://github.com/junjiem/dat/blob/main/project.yaml), and provide the four required parameters: `endpoint`, `deployment-id`, `api-version`, and `api-key`.**

DAT (Data-Assisted Tool) uses a modular plugin architecture for Large Language Models (LLMs) that allows you to configure Azure OpenAI as the LLM provider through a factory-based configuration system. The Azure integration is implemented in the `dat-llm-azure-openai` module, which exposes the `AzureOpenAiChatModelFactory` class to handle authentication, model parameters, and streaming capabilities.

## Prerequisites and Required Configuration Options

Before configuring Azure OpenAI, ensure you have an active Azure OpenAI resource with a deployed model. The `AzureOpenAiChatModelFactory` located at [`dat-llms/dat-llm-azure-openai/src/main/java/ai/dat/llm/azure/AzureOpenAiChatModelFactory.java`](https://github.com/junjiem/dat/blob/main/dat-llms/dat-llm-azure-openai/src/main/java/ai/dat/llm/azure/AzureOpenAiChatModelFactory.java) requires four mandatory configuration options:

| Option | Type | Description |
|--------|------|-------------|
| `endpoint` | `String` | Azure endpoint URL (e.g., `https://{your-resource}.openai.azure.com`) |
| `deployment-id` | `String` | The deployment name of your Azure OpenAI model |
| `api-version` | `String` | Azure OpenAI API version (e.g., `2023-07-01-preview`) |
| `api-key` | `String` | Azure subscription key for authentication |

Optional parameters include `temperature`, `top-p`, `max-tokens` (default 4096), and `timeout` for request handling.

## Step-by-Step Configuration

### Add the Maven Dependency

Include the Azure OpenAI module in your project [`pom.xml`](https://github.com/junjiem/dat/blob/main/pom.xml):

```xml
<dependency>
    <groupId>cn.hexinfo</groupId>
    <artifactId>dat-llm-azure-openai</artifactId>
    <version>${dat.version}</version>
</dependency>

```

This dependency is defined in [`dat-llms/dat-llm-azure-openai/pom.xml`](https://github.com/junjiem/dat/blob/main/dat-llms/dat-llm-azure-openai/pom.xml) and transitively includes LangChain4j's Azure OpenAI client libraries.

### Configure the Model in project.yaml

Declare your Azure OpenAI model in the `models` section of your DAT project configuration:

```yaml
models:
  - name: azure-gpt4
    provider: azure-openai
    endpoint: https://myresource.openai.azure.com
    deployment-id: gpt-4-deployment
    api-version: 2023-07-01-preview
    api-key: ${AZURE_OPENAI_KEY}
    temperature: 0.7
    max-tokens: 4096

```

The `provider: azure-openai` value must match the `IDENTIFIER` constant defined in `AzureOpenAiChatModelFactory`. The factory uses `FactoryUtil.validateFactoryOptions` to ensure all required parameters are present before instantiation.

### Reference the Model in Your Agent

Connect the configured model to an agent or pipeline:

```yaml
agents:
  default:
    model: azure-gpt4
    # additional agent configuration

```

When DAT initializes, the `ChatModelFactory` interface (defined in [`dat-core/src/main/java/ai/dat/core/factories/ChatModelFactory.java`](https://github.com/junjiem/dat/blob/main/dat-core/src/main/java/ai/dat/core/factories/ChatModelFactory.java)) enables runtime discovery of the Azure implementation through the service loader pattern configured in `META-INF/services/ai.dat.core.factories.ChatModelFactory`.

## Understanding the Azure OpenAI Factory Architecture

The `AzureOpenAiChatModelFactory` implements the `ChatModelFactory` interface and acts as a bridge between DAT's configuration system and LangChain4j's Azure client. When `create()` or `createStream()` is invoked, the factory:

1. Validates required options using `FactoryUtil.validateFactoryOptions`
2. Extracts configuration values from the `ReadableConfig` object
3. Constructs either `AzureOpenAiChatModel` or `AzureOpenAiStreamingChatModel` using LangChain4j's builder pattern (lines 57-99 of the factory source)

The factory supports both synchronous and streaming chat completions, with optional parameters defaulting to sensible values when not specified in the YAML configuration.

## Java Code Example: Running a DAT Project with Azure OpenAI

The following example demonstrates programmatically executing a DAT agent configured with Azure OpenAI:

```java
import ai.dat.boot.ProjectRunner;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Map;

public class AzureOpenAiDemo {
    public static void main(String[] args) {
        // Absolute path to DAT project containing the azure-openai configuration
        var projectPath = Paths.get("/path/to/dat-project").toAbsolutePath();
        
        // Environment variables for secret interpolation
        Map<String, Object> vars = Map.of("AZURE_OPENAI_KEY", System.getenv("AZURE_OPENAI_KEY"));
        
        // Initialize runner for the "default" agent
        var runner = new ProjectRunner(projectPath, "default", vars);
        
        // Execute query - automatically routed to Azure OpenAI
        var action = runner.ask("Analyze Q1 2024 sales trends");
        action.forEach(event -> System.out.print(event.getIncrementalContent().orElse("")));
    }
}

```

This example uses `ProjectRunner` from the DAT SDK to load the configuration, instantiate the `AzureOpenAiChatModelFactory`, and execute streaming chat completions against your Azure deployment.

## Summary

- **Add dependency**: Include `dat-llm-azure-openai` (groupId: `cn.hexinfo`) in your Maven project to enable Azure OpenAI support.
- **Configure YAML**: Set `provider: azure-openai` with required fields `endpoint`, `deployment-id`, `api-version`, and `api-key` in your [`project.yaml`](https://github.com/junjiem/dat/blob/main/project.yaml) models section.
- **Factory validation**: The `AzureOpenAiChatModelFactory` validates configuration via `FactoryUtil.validateFactoryOptions` before constructing the LangChain4j client.
- **Agent binding**: Reference the configured model name in your agent definition to route LLM calls through Azure OpenAI.

## Frequently Asked Questions

### What is the exact provider string required for Azure OpenAI configuration?

The provider string must be exactly `azure-openai`. This value is defined as the `IDENTIFIER` constant in [`AzureOpenAiChatModelFactory.java`](https://github.com/junjiem/dat/blob/main/AzureOpenAiChatModelFactory.java) located at [`dat-llms/dat-llm-azure-openai/src/main/java/ai/dat/llm/azure/AzureOpenAiChatModelFactory.java`](https://github.com/junjiem/dat/blob/main/dat-llms/dat-llm-azure-openai/src/main/java/ai/dat/llm/azure/AzureOpenAiChatModelFactory.java). Any deviation from this string will result in a "provider not found" error during DAT initialization.

### How does DAT handle authentication with Azure OpenAI?

DAT passes the `api-key` configuration value directly to LangChain4j's `AzureOpenAiChatModel.builder()` method. As implemented in lines 57-99 of [`AzureOpenAiChatModelFactory.java`](https://github.com/junjiem/dat/blob/main/AzureOpenAiChatModelFactory.java), the factory extracts the key from the YAML configuration and sets it via the builder's `apiKey()` method. For production deployments, use environment variable interpolation (e.g., `${AZURE_OPENAI_KEY}`) rather than hardcoding credentials in YAML files.

### Can I use both streaming and non-streaming modes with Azure OpenAI in DAT?

Yes. The `AzureOpenAiChatModelFactory` implements both `create()` and `createStream()` methods from the `ChatModelFactory` interface. When your agent or pipeline requests a streaming response, the factory instantiates `AzureOpenAiStreamingChatModel`; for standard requests, it returns `AzureOpenAiChatModel`. Both classes are part of the LangChain4j Azure integration and support identical configuration parameters.

### What happens if I omit a required configuration option?

DAT validates factory options using `FactoryUtil.validateFactoryOptions` before attempting to create the model instance. If any of the four required options (`endpoint`, `deployment-id`, `api-version`, `api-key`) are missing from your YAML configuration, the validation throws an exception during project initialization, preventing the application from starting with an incomplete LLM configuration.