Azure
Verified : Automated tests passed for: Configuration files: The configuration files on this page were checked against their schema. End-to-end run: Every step ran in a fresh test environment and the results were checked.Route agentgateway LLM traffic to models hosted on Microsoft Azure AI.
Configure Microsoft Azure AI as an LLM provider in agentgateway.
Authentication
Before you can use Azure as an LLM provider, you must authenticate by using one of the standard Azure authentication methods. In standalone mode, this authentication is configured with llm.models[] fields (for example, params.apiKey or auth.azure). In routing-based configurations, use policies.backendAuth.azure.
Important
Azure CLI authentication requires az or azd to be installed and signed in. Agentgateway calls the CLI when it needs a token. It does not open an interactive flow or run az login or azd auth login for you. Agentgateway does not bundle either command. Mounting a credential directory such as ~/.azure makes cached login state available inside the container, but it does not install the CLI. Use Azure CLI authentication only when running agentgateway directly on your local machine. If agentgateway runs in a container, use an API key, client secret, managed identity, or workload identity.
Use a least-privilege role for Azure AI Foundry
When the gateway authenticates to Azure AI Foundry with a Microsoft Entra ID token, such as with implicit authentication, a managed identity, or workload identity, Azure checks the roles of that identity on the Foundry resource. API keys are not checked against Azure roles. Built-in roles such as Foundry User (previously Azure AI User) and Cognitive Services User grant every data action on the resource, including agents, fine-tuning, files, and evaluations. To limit the identity to the requests that the gateway sends, create a custom role.
The custom role in the following steps allows chat completions and Claude requests. It does not allow other request types, such as Responses or embeddings requests.
The custom role also does not allow Decisions and SystemOne requests. For Azure AI Foundry, the gateway sends these requests to https://{resourceName}.cognitiveservices.azure.com with a token for the https://cognitiveservices.azure.com/.default scope, which these steps do not describe.
Save the following custom role definition to a file, such as
foundry-inference-role.json. Replace<subscription-id>with the ID of your Azure subscription.{ "Name": "agentgateway Foundry Inference", "IsCustom": true, "Description": "Least-privilege inference for agentgateway against an Azure AI Foundry resource", "Actions": [], "NotActions": [], "DataActions": [ "Microsoft.CognitiveServices/accounts/AIServices/providers/action", "Microsoft.CognitiveServices/accounts/OpenAI/deployments/chat/completions/action" ], "NotDataActions": [], "AssignableScopes": ["/subscriptions/<subscription-id>"] }The role has no control plane permissions (
Actions) because the gateway does not call Azure Resource Manager to list deployments, read keys, or read the resource. The gateway sends requests tohttps://{resourceName}.services.ai.azure.comwith a token for thehttps://ai.azure.com/.defaultscope. The following table shows the data plane permission (DataActions) that each request type requires.Request type Upstream path Data action Chat completions /api/projects/{projectName}/openai/v1/chat/completionsMicrosoft.CognitiveServices/accounts/OpenAI/deployments/chat/completions/actionClaude token counting /anthropic/v1/messages/count_tokensMicrosoft.CognitiveServices/accounts/AIServices/providers/actionClaude Messages /anthropic/v1/messagesMicrosoft.CognitiveServices/accounts/AIServices/providers/actionIf
projectNameis not set, the gateway uses the resource name as the project name in the chat completions path.Create the custom role.
az role definition create --role-definition foundry-inference-role.jsonAssign the custom role to the identity that the gateway uses. Assign the role at the scope of the Foundry resource, not a Foundry project. The Claude paths are resource-level paths with no project in the URL, so a role that is assigned only to a project might not authorize Claude requests. For a managed identity, use the principal ID, also called the object ID, of the identity.
az role assignment create \ --assignee-object-id <identity-principal-id> \ --assignee-principal-type ServicePrincipal \ --role "agentgateway Foundry Inference" \ --scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.CognitiveServices/accounts/<resource-name>"Role assignments can take several minutes to take effect.
Send a request through the gateway for each request type that you use, including Claude Messages requests. If a request fails with a
401error, find the request type in the table in step 1. Check that the role includes the data action for that request type. Also check that the role is assigned at the scope of the Foundry resource, as described in step 3. The error message might name the missing data action.
For more information, see Role-based access control for Microsoft Foundry and Azure custom roles.
Configuration
Azure supports two endpoint types:
- Azure AI Foundry (
foundry): Connect to Azure AI Foundry project endpoints at{resourceName}.services.ai.azure.com. - Azure OpenAI (
openAI): Connect directly to Azure OpenAI Service deployments at{resourceName}.openai.azure.com.
You can add the model in the UI or in your configuration file.
To add the model in the UI, follow these steps. The steps create the same models as the Config file tab.
Optional: To authenticate with an API key, set your API key in the
AZURE_API_KEYenvironment variable. The UI checks that the variable exists when you save the model.export AZURE_API_KEY='<your-api-key>'Create a configuration file with an empty
llmsection, and start agentgateway in the same terminal. Without anllmsection, the UI does not show the LLM > Models page.cat > config.yaml <<'EOF' # yaml-language-server: $schema=https://agentgateway.dev/schema/config llm: models: [] EOF agentgateway -f config.yamlOpen LLM > Models, such as http://localhost:15000/ui/llm/models, and click Add model.
From the Provider dropdown, select Azure.
In the Incoming model match field, replace the default
azure/*with the model name to match, such as*orgpt-4.1.For the Azure credentials, select one of the following options.
- Default: Uses implicit Entra ID authentication.
- Managed: Uses a managed identity. Optionally, enter the client ID of a user-assigned identity.
- API key: Select Env var, and enter
AZURE_API_KEY.
Enter the Azure resource name, such as
your-resource-name.For the Azure resource type, select Foundry or OpenAI. For Foundry, you can also enter the Azure project name, such as
your-project-name. If you leave it empty, agentgateway uses the resource name.Optional: Enter an Azure API version. Leave the field empty to use the default.


Click Save model.
The API key option saves the key in params.apiKey. The Foundry (API key) example in the Config file tab uses an auth.key block instead, which sends the key in the api-key header. To write that block, click the Raw icon (<>) in the drawer header, or use the Config file tab.
Whether the UI can save depends on your storage mode. For more information, see Save changes from the UI.
Advanced configuration
For advanced Azure AI scenarios, use the traditional listener/route configuration format. The following tabs show examples for different authentication methods.
Azure AI Foundry with implicit auth: Use DefaultAzureCredential to automatically detect credentials from the environment (Azure CLI, managed identity, workload identity, or environment variables).
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
gateways:
default:
port: 3000
routes:
- matches:
- path:
pathPrefix: /azure
backends:
- ai:
name: azure
provider:
azure:
resourceName: "your-resource-name"
projectName: "your-project-name"
resourceType: foundry
model: gpt-4.1Review the following example configuration.
| Setting | Description |
|---|---|
ai.name | The name of the LLM provider for this AI backend. |
ai.provider.azure.resourceName | The Azure resource name used to construct the endpoint hostname. |
ai.provider.azure.resourceType | The endpoint type: foundry for Azure AI Foundry, or openAI for Azure OpenAI Service. |
ai.provider.azure.projectName | The Foundry project name. Optional. If omitted, defaults to resourceName. |
ai.provider.azure.model | Optionally set the model to use for requests. If set, any models in the request are overwritten. If not set, the request must include the model to use. |
backendAuth.azure.implicit | Use implicit authentication via DefaultAzureCredential, which automatically detects credentials from the environment. |
Use Claude models on Azure AI Foundry
Azure AI Foundry hosts Anthropic Claude models at native Anthropic endpoints. When you set azureResourceType: foundry and a model name that starts with claude-, agentgateway automatically routes requests to the Anthropic-native path (/anthropic/v1/messages) instead of the OpenAI-compatible path, and injects the required anthropic-version header. No extra configuration is needed beyond specifying a Claude model name.
Note
For more information about Claude models on Azure AI Foundry, see the Microsoft documentation.
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
gateways:
default:
port: 3000
routes:
- name: azure
matches:
- path:
pathPrefix: /azure-anthropic #prefix example
backends:
- ai:
name: azure
provider:
azure:
resourceName: your-foundry-resource
projectName: your-project-name
resourceType: foundry
model: claude-sonnet-4-6
policies:
backendAuth:
key:
value: your-api-key| Setting | Description |
|---|---|
ai.name | A name for the AI backend. |
ai.provider.azure.resourceName | The Azure AI Foundry resource name used to construct the endpoint hostname. |
ai.provider.azure.projectName | The Foundry project name. Optional. If omitted, defaults to resourceName. |
ai.provider.azure.resourceType | Set to foundry to use Azure AI Foundry endpoints. |
ai.provider.azure.model | The Claude model deployment to send requests to, such as claude-sonnet-4-6. |
policies.backendAuth.key.value | The Azure AI Foundry API key. You can reference environment variables using the $VAR_NAME syntax. The key is automatically sent in the Authorization header. For other authentication methods, see Backend authentication. |
After running agentgateway with this configuration, send a request to verify:
curl -X POST http://localhost:4000/azure-anthropic \
-H "Content-Type: application/json" \
-d '{
"max_tokens": 256,
"messages": [{"role": "user", "content": "Hello!"}]
}'Use Decisions on Azure
Azure models can answer classification questions about an input, such as which of several choices fits best or how likely a statement is true. agentgateway accepts two client request formats for these models:
- Decisions API (
/v1/decisions): The OpenAI-compatible format, withpredicate,choice, andscorequestion types. For another example of this API, see the Jev guardrail guide. - SystemOne (
/v1/systemone): The TypeSafe format, with correspondingnoul,choice, andscorequestion types.
Choose the Azure endpoint that hosts your model. Agentgateway converts requests and responses to the upstream endpoint’s native format.
- Azure OpenAI: Deploy a model that supports the Azure OpenAI Decisions API, such as
gpt-6-luna. Azure OpenAI receives both client formats at/openai/v1/decisions: Decisions requests are sent unchanged, and SystemOne requests are converted to Decisions. - Azure AI Foundry: Deploy Microsoft-Decision-1 in your Foundry resource. Foundry receives both client formats at
https://{resourceName}.cognitiveservices.azure.com/providers/microsoft/v1/systemone: SystemOne requests are sent unchanged, and Decisions requests are converted to SystemOne.
Before you begin, sign in with the Azure CLI or the Azure Developer CLI as an identity that has inference access to the resource.
Save the following configuration as
Review the following example configuration.config-decisions.yaml. Choose the tab for the endpoint that hosts your model, and replace the resource and deployment names with your own values.Review the following table to understand this configuration.# yaml-language-server: $schema=https://agentgateway.dev/schema/config llm: models: - auth: azure: developerImplicit: {} name: azure-decisions params: azureResourceName: my-openai-resource azureResourceType: openAI model: my-decision-deployment provider: azure port: 3000Setting Description nameThe model name that clients send in the modelfield. This name is not the Azure deployment name. A request with any other model name returns a404error.providerSet to azurefor Azure.auth.azure.developerImplicitAuthenticate with the credentials from your Azure CLI or Azure Developer CLI sign-in. params.azureResourceNameThe Azure resource name used to construct the endpoint hostname. params.azureResourceTypeSet to openAIfor Azure OpenAI orfoundryfor Azure AI Foundry.params.modelThe name of your Azure deployment. agentgateway sends this name upstream and replaces the modelvalue in the client request.Both request paths are served from the same model. You do not need to configure a route for each path.
Validate the configuration, then start agentgateway.
agentgateway --validate-only -f config-decisions.yaml agentgateway -f config-decisions.yamlIn another terminal, send a predicate question through the Decisions API.
curl --fail-with-body --max-time 120 http://localhost:3000/v1/decisions \ -H 'Content-Type: application/json' \ -d '{ "input": "I was charged twice. Can I get a refund?", "model": "azure-decisions", "questions": [{ "instructions": "Is the customer asking for a refund?", "name": "refund_requested", "type": "predicate" }] }'The response includes the probability that the customer requested a refund and the request’s token usage. For more information about the request format, see Decisions.
Send the same question in the SystemOne client format. SystemOne takes the input in
state, the questions as a map keyed by name, and returns ananswersmap.curl --fail-with-body --max-time 120 http://localhost:3000/v1/systemone \ -H 'Content-Type: application/json' \ -d '{ "model": "azure-decisions", "questions": { "refund_requested": { "instructions": "Is the customer asking for a refund?", "type": "noul" } }, "state": "I was charged twice. Can I get a refund?" }'Note
Prompt guards are disabled for requests in the SystemOne format.
When you finish, stop agentgateway with Ctrl+C.