---
title: "Azure AI Foundry Integration"
source: https://docs.autohand.ai/integrations/azure-foundry
---

# Azure AI Foundry

Enterprise-grade AI models with Azure security, compliance, and regional data residency. Access OpenAI, Llama, Mistral, and more through Azure infrastructure.

## Overview

Azure AI Foundry (formerly Azure AI Studio) provides enterprise access to leading AI models. When integrated with Autohand, you get:

-   Access to GPT-4, GPT-4o, and OpenAI models on Azure
-   Open-source models like Llama 3.1, Mistral, and Phi
-   Enterprise security with API Key, Microsoft Entra ID, or Managed Identity
-   Data residency in your chosen Azure region
-   Compliance certifications (SOC 2, HIPAA, GDPR)
-   Private endpoints and VNet integration

**Enterprise choice:** Azure AI Foundry is ideal for organizations that need Azure compliance, regional data residency, or existing Azure infrastructure integration.

## Setup

Get started with Azure AI Foundry.

### Prerequisites

-   Azure subscription with AI Foundry access
-   Azure AI Foundry project created
-   Model deployment in your project

### Get your credentials

1.  Go to [ai.azure.com](https://ai.azure.com) and sign in
2.  Open your AI Foundry project
3.  Navigate to **Deployments** and select your model
4.  Copy the endpoint URL and API key

### Configure Autohand

``` bash
# Set environment variables
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"
export AZURE_OPENAI_KEY="xxxxxxxxxxxxxxxxxxxxxxxx"
export AZURE_OPENAI_DEPLOYMENT="gpt-4o"
export AZURE_OPENAI_API_VERSION="2024-10-21"

# Or use the interactive wizard
autohand
/model
# Select "azure" from the provider list and follow the prompts
```

Verify your configuration:

``` bash
# Start with Azure provider
autohand --provider azure --model gpt-4o

# Test with a prompt
autohand --prompt "Hello, which model are you?"
```

## CLI configuration

Configure Azure AI Foundry in your `~/.autohand/config.json`. Autohand supports two styles: structured fields (recommended) or a direct base URL override.

### Structured configuration (recommended)

``` json
{
  "provider": "azure",
  "azure": {
    "model": "gpt-4o",
    "apiKey": "your-azure-api-key",
    "resourceName": "your-resource",
    "deploymentName": "gpt-4o",
    "apiVersion": "2024-10-21",
    "authMethod": "api-key"
  }
}
```

### Base URL override

For proxies, custom endpoints, or Azure AI Foundry model-as-a-service:

``` json
{
  "provider": "azure",
  "azure": {
    "model": "gpt-4o",
    "apiKey": "your-azure-api-key",
    "baseUrl": "https://your-resource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21"
  }
}
```

### Configuration options

| Option | Description | Default |
|---|---|---|
| model | Model name (for display and model switching) | gpt-4o |
| apiKey | Your Azure API key | - |
| resourceName | Azure resource name (from https://{name}.openai.azure.com) | - |
| deploymentName | Model deployment name in Azure | - |
| apiVersion | Azure OpenAI API version | 2024-10-21 |
| authMethod | Authentication method: api-key, entra-id, or managed-identity | api-key |
| baseUrl | Full endpoint URL override (bypasses resourceName/deploymentName) | - |

### Environment variables

All configuration options can be set via environment variables. These override values in `config.json`:

| Variable | Maps to |
|---|---|
| AZURE_OPENAI_KEY | azure.apiKey |
| AZURE_OPENAI_ENDPOINT | azure.baseUrl |
| AZURE_OPENAI_DEPLOYMENT | azure.deploymentName |
| AZURE_OPENAI_API_VERSION | azure.apiVersion |
| AZURE_TENANT_ID | azure.tenantId |
| AZURE_CLIENT_ID | azure.clientId |
| AZURE_CLIENT_SECRET | azure.clientSecret |

## Authentication methods

Autohand supports three authentication methods for Azure OpenAI. Choose based on your security requirements.

### API Key (default)

The simplest option. Use the API key from your Azure OpenAI resource.

``` json
{
  "provider": "azure",
  "azure": {
    "authMethod": "api-key",
    "apiKey": "your-azure-api-key",
    "resourceName": "your-resource",
    "deploymentName": "gpt-4o",
    "apiVersion": "2024-10-21"
  }
}
```

### Microsoft Entra ID (Azure AD)

Use OAuth2 client credentials for enterprise environments. Requires an [app registration in Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app).

``` json
{
  "provider": "azure",
  "azure": {
    "authMethod": "entra-id",
    "tenantId": "your-tenant-id",
    "clientId": "your-client-id",
    "clientSecret": "your-client-secret",
    "resourceName": "your-resource",
    "deploymentName": "gpt-4o",
    "apiVersion": "2024-10-21"
  }
}
```

**App permissions:** Your Entra ID app registration needs the `Cognitive Services OpenAI User` role assigned on the Azure OpenAI resource.

### Managed Identity

For workloads running inside Azure (VMs, App Service, AKS, etc.). No credentials needed — Azure handles authentication automatically via the [Instance Metadata Service (IMDS)](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview).

``` json
{
  "provider": "azure",
  "azure": {
    "authMethod": "managed-identity",
    "resourceName": "your-resource",
    "deploymentName": "gpt-4o",
    "apiVersion": "2024-10-21"
  }
}
```

**Production recommended:** Managed Identity is the most secure option for Azure-hosted workloads. No secrets to rotate or leak.

## Available models

Azure AI Foundry supports multiple model families.

### OpenAI models

| Model | Context | Best for |
|---|---|---|
| gpt-4o | 128K | Most capable, multimodal |
| gpt-4o-mini | 128K | Fast and cost-effective |
| gpt-4-turbo | 128K | Complex reasoning |

### Open-source models

| Model | Context | Best for |
|---|---|---|
| Meta-Llama-3.1-70B | 128K | Open-source, flexible |
| Mistral-Large-2 | 128K | Efficient reasoning |
| Phi-3-medium | 128K | Microsoft research model |

## Best practices

-   **Use Managed Identity**: Prefer managed identities over API keys for Azure-hosted production workloads.
-   **Use Entra ID**: For non-Azure environments, use Entra ID app credentials instead of API keys.
-   **Choose your region**: Deploy models in regions that meet your data residency requirements.
-   **Monitor usage**: Use Azure Cost Management to track AI spending.
-   **Set quotas**: Configure TPM (tokens per minute) limits to control costs.
-   **Rotate API keys**: If using API keys, rotate them regularly via the Azure portal.

## Resources

-   [Azure AI Foundry Portal](https://ai.azure.com)
-   [Azure AI Services](https://azure.microsoft.com/en-us/products/ai-services)
-   [Azure OpenAI Documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/)
-   [Azure OpenAI API Reference](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference)
-   [Microsoft Entra ID (Azure AD) Platform](https://learn.microsoft.com/en-us/entra/identity-platform/)
-   [Managed Identities for Azure Resources](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview)
-   [Register an Application in Entra ID](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app)
-   [Azure OpenAI Pricing](https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/)
-   [Azure Status](https://status.azure.com)

## Troubleshooting

### Common issues

| Issue | Solution |
|---|---|
| 401 Unauthorized | Check API key or Azure AD credentials |
| 404 Deployment not found | Verify deployment name matches exactly |
| 429 Rate limited | Increase TPM quota in Azure portal |
| Region not available | Deploy model in a supported region |

### Debug mode

``` bash
# Enable verbose logging
AUTOHAND_DEBUG=true autohand --provider azure

# Test Azure endpoint directly
curl "https://your-resource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21" \
  -H "api-key: ${AZURE_OPENAI_KEY}" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Hello"}]}'
```