AzureAIFoundryExtensions Methods
Class Methods 6 members
Provides extension methods for adding the Azure AI Foundry resources to the application model.
AddAzureAIFoundry(IDistributedApplicationBuilder, string) Section titled AddAzureAIFoundry(IDistributedApplicationBuilder, string) extension IResourceBuilder<AzureAIFoundryResource> Adds an Azure OpenAI resource to the application model.
public static class AzureAIFoundryExtensions{ public static IResourceBuilder<AzureAIFoundryResource> AddAzureAIFoundry( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. Returns
IResourceBuilder<AzureAIFoundryResource> A reference to the ApplicationModel.IResourceBuilder`1. AddDeployment(IResourceBuilder<AzureAIFoundryResource>, string, string, string, string) Section titled AddDeployment(IResourceBuilder<AzureAIFoundryResource>, string, string, string, string) extension IResourceBuilder<AzureAIFoundryDeploymentResource> Adds and returns an Azure AI Foundry Deployment resource to the application model.
public static class AzureAIFoundryExtensions{ public static IResourceBuilder<AzureAIFoundryDeploymentResource> AddDeployment( this IResourceBuilder<AzureAIFoundryResource> builder, string name, string modelName, string modelVersion, string format) { // ... }}Parameters
builder IResourceBuilder<AzureAIFoundryResource> The Azure AI Foundry resource builder. name string The name of the Azure AI Foundry Deployment resource. modelName string The name of the model to deploy. modelVersion string The version of the model to deploy. format string The format of the model to deploy. Returns
IResourceBuilder<AzureAIFoundryDeploymentResource> A reference to the ApplicationModel.IResourceBuilder`1. AddDeployment(IResourceBuilder<AzureAIFoundryResource>, string, AIFoundryModel) Section titled AddDeployment(IResourceBuilder<AzureAIFoundryResource>, string, AIFoundryModel) extension IResourceBuilder<AzureAIFoundryDeploymentResource> Adds and returns an Azure AI Foundry Deployment resource to the application model using a
AIFoundryModel. public static class AzureAIFoundryExtensions{ public static IResourceBuilder<AzureAIFoundryDeploymentResource> AddDeployment( this IResourceBuilder<AzureAIFoundryResource> builder, string name, AIFoundryModel model) { // ... }}Parameters
builder IResourceBuilder<AzureAIFoundryResource> The Azure AI Foundry resource builder. name string The name of the Azure AI Foundry Deployment resource. model AIFoundryModel The model descriptor, using the AIFoundryModel class like so: aiFoundry.AddDeployment(name: "chat", model: AIFoundryModel.OpenAI.Gpt5Mini)Returns
IResourceBuilder<AzureAIFoundryDeploymentResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
Create a deployment for the OpenAI GTP-5-mini model:
var builder = DistributedApplication.CreateBuilder(args);
var aiFoundry = builder.AddAzureAIFoundry("aiFoundry");var gpt5mini = aiFoundry.AddDeployment("chat", AIFoundryModel.OpenAI.Gpt5Mini);RunAsFoundryLocal(IResourceBuilder<AzureAIFoundryResource>) Section titled RunAsFoundryLocal(IResourceBuilder<AzureAIFoundryResource>) extension IResourceBuilder<AzureAIFoundryResource> Adds a Foundry Local resource to the distributed application builder.
public static class AzureAIFoundryExtensions{ public static IResourceBuilder<AzureAIFoundryResource> RunAsFoundryLocal( this IResourceBuilder<AzureAIFoundryResource> builder) { // ... }}Parameters
builder IResourceBuilder<AzureAIFoundryResource> The distributed application builder. Returns
IResourceBuilder<AzureAIFoundryResource> A resource builder for the Foundry Local resource. WithProperties(IResourceBuilder<AzureAIFoundryDeploymentResource>, Action<AzureAIFoundryDeploymentResource>) Section titled WithProperties(IResourceBuilder<AzureAIFoundryDeploymentResource>, Action<AzureAIFoundryDeploymentResource>) extension IResourceBuilder<AzureAIFoundryDeploymentResource> Allows setting the properties of an Azure AI Foundry Deployment resource.
public static class AzureAIFoundryExtensions{ public static IResourceBuilder<AzureAIFoundryDeploymentResource> WithProperties( this IResourceBuilder<AzureAIFoundryDeploymentResource> builder, Action<AzureAIFoundryDeploymentResource> configure) { // ... }}Parameters
builder IResourceBuilder<AzureAIFoundryDeploymentResource> The Azure AI Foundry Deployment resource builder. configure Action<AzureAIFoundryDeploymentResource> A method that can be used for customizing the AzureAIFoundryDeploymentResource. Returns
IResourceBuilder<AzureAIFoundryDeploymentResource> A reference to the ApplicationModel.IResourceBuilder`1. WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureAIFoundryResource>, CognitiveServicesBuiltInRole[]) Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureAIFoundryResource>, CognitiveServicesBuiltInRole[]) extension IResourceBuilder<T> Assigns the specified roles to the given resource, granting it the necessary permissions on the target Azure AI Foundry resource. This replaces the default role assignments for the resource.
public static class AzureAIFoundryExtensions{ public static IResourceBuilder<T> WithRoleAssignments<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureAIFoundryResource> target, params CognitiveServicesBuiltInRole[] roles) { // ... }}Parameters
builder IResourceBuilder<T> The resource to which the specified roles will be assigned. target IResourceBuilder<AzureAIFoundryResource> The target Azure AI Foundry resource. roles CognitiveServicesBuiltInRole[] The built-in Cognitive Services roles to be assigned. Returns
IResourceBuilder<T> The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments. Remarks
Assigns the CognitiveServicesOpenAIContributor role to the 'Projects.Api' project.
var builder = DistributedApplication.CreateBuilder(args);
var aiFoundry = builder.AddAzureAIFoundry("aiFoundry");
var api = builder.AddProject<Projects.Api>("api") .WithRoleAssignments( aiFoundry, CognitiveServicesBuiltInRole.CognitiveServicesOpenAIContributor) .WithReference(aiFoundry);