> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Azure AI Foundry

> Trace Azure OpenAI SDK calls and use Azure AI Foundry models in Braintrust

If you are a coding agent, prefer the Braintrust [`bt` CLI](/reference/cli/quickstart) for repeatable, scriptable work: running evals, instrumenting code, querying logs, syncing data, managing functions, and configuring coding agents. Use the MCP server for reasoning over Braintrust data in conversation, such as ad-hoc lookups and exploration from your IDE.

Braintrust integrates with [Azure AI Foundry](https://ai.azure.com/), giving you access to OpenAI models and the full [Azure model catalog](https://ai.azure.com/explore/models), including models from Grok, Anthropic, DeepSeek, and more.

<Note>
  Azure OpenAI Service is also supported through the same configuration.
</Note>

<View title=".NET" icon="https://img.logo.dev/dotnet.microsoft.com?token=pk_BdcHD9e5SCW3j1rnJkNyMQ">
  <h2 id="tracing-dotnet">
    Tracing
  </h2>

  Trace Azure OpenAI chat completions with the `Braintrust.Sdk.AzureOpenAI` package, which instruments the `AzureOpenAIClient` from `Azure.AI.OpenAI`.

  <h3 id="setup-dotnet">
    Setup
  </h3>

  Install the Braintrust SDK and the Azure OpenAI integration, then set your API keys.

  <Steps>
    <Step title="Install packages">
      ```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
      dotnet add package Braintrust.Sdk
      dotnet add package Braintrust.Sdk.AzureOpenAI
      ```
    </Step>

    <Step title="Set environment variables">
      ```bash title=".env" theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
      BRAINTRUST_API_KEY=<your-braintrust-api-key>
      AZURE_OPENAI_ENDPOINT=<your-azure-openai-endpoint>
      AZURE_OPENAI_API_KEY=<your-azure-openai-api-key>
      ```
    </Step>
  </Steps>

  <h3 id="manual-instrumentation-dotnet">
    Manual instrumentation
  </h3>

  To trace Azure OpenAI calls, create an instrumented client with `WrapAzureOpenAI`, then use it as you normally would. Pass your Azure deployment name to `GetChatClient`.

  ```csharp #skip-compile theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  using Azure.AI.OpenAI;
  using Braintrust.Sdk;
  using Braintrust.Sdk.AzureOpenAI;
  using OpenAI.Chat;

  var braintrust = Braintrust.Sdk.Braintrust.Get();
  var activitySource = braintrust.GetActivitySource();

  var endpoint = new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"));
  var apiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY");

  // Create an instrumented Azure OpenAI client
  var client = BraintrustAzureOpenAI.WrapAzureOpenAI(activitySource, endpoint, apiKey);

  // Use your Azure deployment name, not the underlying model name
  var chatClient = client.GetChatClient("gpt-5-mini");
  var response = await chatClient.CompleteChatAsync(
      new ChatMessage[]
      {
          new UserChatMessage("What is the capital of France?")
      });
  ```

  To instrument an `AzureOpenAIClient` you already created, call `.WithBraintrust(activitySource)` on it instead. For Microsoft Entra ID authentication, pass a `TokenCredential` to `WrapAzureOpenAI` in place of the API key.

  <h3 id="what-traced-dotnet">
    What Braintrust traces
  </h3>

  `Braintrust.Sdk.AzureOpenAI` reuses the OpenAI instrumentation pipeline, so Azure OpenAI calls capture the same data:

  * Chat completion spans (`Chat Completion`), with input and output messages, request and response model, and token usage (prompt, completion, and total).
  * Request parameters as metadata, such as temperature, max tokens, top-p, stop sequences, tools, tool choice, and response format.
  * Time to first token for each completion.
  * Errors on the span, including the exception details.

  <h3 id="tracing-resources-dotnet">
    Tracing resources
  </h3>

  * [Braintrust C# SDK reference](/sdks/csharp/api-reference)
  * [Braintrust .NET SDK on GitHub](https://github.com/braintrustdata/braintrust-sdk-dotnet)
  * [Azure OpenAI in Azure AI Foundry](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/)
</View>

## Add Azure AI Foundry as an AI provider

Add Azure AI Foundry as an AI provider to use its models from the Braintrust playground, prompts, and the gateway.

### Deploy the model

In Azure AI Foundry, [deploy the model](https://learn.microsoft.com/en-us/azure/foundry/foundry-models/how-to/deploy-foundry-models) you want to use.

### Configure the integration

1. Go to **<Icon icon="settings-2" /> Settings** > [**<Icon icon="sparkle" /> AI providers**](https://www.braintrust.dev/app/~/configuration/org/secrets).

2. Add a new [organization or project provider](/admin/ai-providers) and choose **Azure**.

3. Choose your authentication method:

   * **API Key**: Paste your Azure API key.
   * **Entra API (Azure AD)**: Provide your Entra ID credentials to authenticate via Azure Active Directory.
   * **Microsoft Entra Workload Identity**: Exchange a Braintrust-signed OIDC token for a Microsoft Entra access token, instead of storing a long-lived Azure credential in Braintrust.

   <Note>
     API keys are stored as one-way cryptographic hashes, never in plaintext.
   </Note>

   <Note>
     Microsoft Entra Workload Identity is available only for organization-level providers on Braintrust-hosted organizations with the Braintrust gateway enabled. Project-level providers and self-hosted deployments must use **API Key** or **Entra API (Azure AD)** authentication.
   </Note>

4. If you chose **Microsoft Entra Workload Identity**, configure Microsoft Entra ID and Braintrust with the matching setup values:

   1. [Create or choose an app registration](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app) in Microsoft Entra ID.
      * Copy the **Application (client) ID** and paste it into the **Client ID** field in Braintrust.
      * Copy the **Directory (tenant) ID** and paste it into the **Tenant ID** field in Braintrust.
   2. [Add a flexible federated credential to the app registration](https://learn.microsoft.com/en-us/entra/workload-id/workload-identities-set-up-flexible-federated-identity-credential). Go to **Manage > Certificates & secrets > Federated credentials**, add an **Other issuer** credential:
      * Set **Issuer** to the issuer shown in Braintrust.
      * Set **Type** to **Explicit subject identifier**.
      * Set **Value** to the subject shown in Braintrust.
      * Set **Audience** to the audience shown in Braintrust.
   3. Grant Azure OpenAI access to the app registration service principal. On the Azure OpenAI or Azure AI services resource behind this provider's API base URL, add the `Cognitive Services OpenAI User` role assignment. You can assign the role on the resource or on the resource group that contains it.
   4. Back in Braintrust, enter additional values that identify your Microsoft Entra setup:
      * **Scope**: The OAuth scope requested from Microsoft Entra. For Azure OpenAI, use `https://cognitiveservices.azure.com/.default`.
      * **Subject suffix**: A stable suffix for this Azure connection. It must match the final part of the federated credential subject.

5. Set **API base URL** to the base URL of your project endpoint in Azure.

   For example, for the project endpoint `https://john-3396-resource.services.ai.azure.com/api/projects/john-3396`, you'd use `https://john-3396-resource.services.ai.azure.com`.

6. Depending on the model you deployed, configure model details:

   * **OpenAI models**: Braintrust's built-in Azure registry includes OpenAI models (such as the GPT series). To access these models through Braintrust, enable **Include the default registry of Azure models**.

   * **Other models**: If you deployed any non-OpenAI model from the [Azure model catalog](https://ai.azure.com/explore/models), such as Grok, Claude, or DeepSeek, configure the model details:

     * Set **Models** to the exact deployment name in Azure.
     * Click <Icon icon="settings-2" /> and select the **Format** based on the API the model supports:

       | API type        | Braintrust format |
       | --------------- | ----------------- |
       | Chat completion | OpenAI            |
       | Responses       | OpenAI            |
       | Messages        | Anthropic         |

     For full configuration options, see [Custom providers](/integrations/ai-providers/custom).

     <Warning>Non-OpenAI models appear in the Braintrust model selector but cannot be used directly from the UI. Use them via the Braintrust API or SDK instead.</Warning>

7. Click **Save**.

### Azure provider resources

* [Azure AI Foundry](https://ai.azure.com/)
* [Azure model catalog](https://ai.azure.com/explore/models)
* [Deploy models in Azure AI Foundry](https://learn.microsoft.com/en-us/azure/foundry/foundry-models/how-to/deploy-foundry-models)
* [Azure OpenAI vs. Microsoft Foundry models](https://learn.microsoft.com/en-us/azure/foundry-classic/foundry-models/faq?view=foundry-classic#what-s-the-difference-between-azure-openai-and-microsoft-foundry-models-?WT.mc_id=AZ-MVP-5000120)
