# AzureApiManagementExtensions Methods

- Package: [Aspire.Hosting.Azure.ApiManagement](/reference/api/csharp/aspire.hosting.azure.apimanagement.md)
- Type: [AzureApiManagementExtensions](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions.md)
- Kind: `Methods`
- Members: `38`

Provides extension methods for adding Azure API Management resources to the application model.

<a id="addapi"></a>
<a id="addapi-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-t-string-string-bool-string"></a>

## AddApi(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<T>, string, string?, bool, string?)

- Name: `AddApi(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<T>, string, string?, bool, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L190-L191)

Adds an API that routes requests to an Aspire compute resource.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> AddApi<T>(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        IResourceBuilder<T> target,
        string path,
        string? displayName = null,
        bool subscriptionRequired = true,
        string? apiName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical API name.
- `target` (`IResourceBuilder<T>`)
  The backend compute resource. It must expose an HTTP or HTTPS endpoint. Internal endpoints require the API Management service to have virtual network connectivity to the target.
- `path` (`string`)
  The public path beneath the API Management gateway hostname.
- `displayName` (`string?`) `optional`
  The API display name. The resource name is used when omitted.
- `subscriptionRequired` (`bool`) `optional`
  Whether callers must provide an API Management subscription key. The default is `true`.
- `apiName` (`string?`) `optional`
  The physical API identifier in API Management. The Aspire resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- A builder for the API resource.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `target` is null.
- `ArgumentException` -- Thrown when a required string is empty.

## Remarks

The generated API contains catch-all operations for supported HTTP methods and paths. The generated policy routes requests through an API Management backend entity whose URL is resolved from the target deployment environment.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addapi-iresourcebuilder-azureapimanagementresource-string-string-string-bool-string"></a>

## AddApi(IResourceBuilder<AzureApiManagementResource>, string, string, string?, bool, string?)

- Name: `AddApi(IResourceBuilder<AzureApiManagementResource>, string, string, string?, bool, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L217)

Adds an API whose backend is configured separately.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> AddApi(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        string path,
        string? displayName = null,
        bool subscriptionRequired = true,
        string? apiName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical API name.
- `path` (`string`)
  The public path beneath the API Management gateway hostname.
- `displayName` (`string?`) `optional`
  The API display name. The resource name is used when omitted.
- `subscriptionRequired` (`bool`) `optional`
  Whether callers must provide an API Management subscription key. The default is `true`.
- `apiName` (`string?`) `optional`
  The physical API identifier in API Management. The Aspire resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- A builder for the API resource.

## Remarks

Configure the API backend with [AzureApiManagementExtensions.WithBackend(IResourceBuilder<AzureApiManagementBackendPoolResource>, IResourceBuilder<AzureApiManagementBackendResource>, int, int)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withbackend-iresourcebuilder-azureapimanagementbackendpoolresource-iresourcebuilder-azureapimanagementbackendresource-int-int) or [AzureApiManagementExtensions.WithBackend(IResourceBuilder<AzureApiManagementBackendPoolResource>, IResourceBuilder<AzureApiManagementBackendResource>, int, int)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withbackend-iresourcebuilder-azureapimanagementbackendpoolresource-iresourcebuilder-azureapimanagementbackendresource-int-int).

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/addApiWithoutTarget`

<a id="addazureapimanagement"></a>
<a id="addazureapimanagement-idistributedapplicationbuilder-string-azureapimanagementoptions"></a>

## AddAzureApiManagement(IDistributedApplicationBuilder, string, AzureApiManagementOptions)

- Name: `AddAzureApiManagement(IDistributedApplicationBuilder, string, AzureApiManagementOptions)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L65-L117)

Adds an Azure API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> AddAzureApiManagement(
        this IDistributedApplicationBuilder builder,
        string name,
        AzureApiManagementOptions options)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The distributed application builder.
- `name` (`string`)
  The name of the Aspire resource.
- `options` ([AzureApiManagementOptions](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementoptions.md))
  The API Management service options.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- A builder for the Azure API Management resource.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `options` is null.
- `ArgumentException` -- Thrown when required option values are empty or capacity is invalid for the selected SKU.

## Examples

```csharp
var apim = builder.AddAzureApiManagement("apim", new()
{
    PublisherEmail = "api-owners@example.com",
    PublisherName = "Contoso APIs",
    Sku = AzureApiManagementSku.StandardV2,
});
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addazureopenaibackend"></a>
<a id="addazureopenaibackend-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-azureopenaideploymentresource-string"></a>

## AddAzureOpenAIBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<AzureOpenAIDeploymentResource>, string?)

- Name: `AddAzureOpenAIBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<AzureOpenAIDeploymentResource>, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementBackendResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L902-L917)

Adds an Azure OpenAI deployment as an API Management backend.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementBackendResource> AddAzureOpenAIBackend(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        IResourceBuilder<AzureOpenAIDeploymentResource> deployment,
        string? backendName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
- `name` (`string`)
- `deployment` (`IResourceBuilder<AzureOpenAIDeploymentResource>`)
- `backendName` (`string?`) `optional`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addbackend"></a>
<a id="addbackend-iresourcebuilder-azureapimanagementresource-string-referenceexpression-azureapimanagementbackendoptions-string"></a>

## AddBackend(IResourceBuilder<AzureApiManagementResource>, string, ReferenceExpression, AzureApiManagementBackendOptions?, string?)

- Name: `AddBackend(IResourceBuilder<AzureApiManagementResource>, string, ReferenceExpression, AzureApiManagementBackendOptions?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementBackendResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L862-L889)

Adds a configurable backend to the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementBackendResource> AddBackend(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        ReferenceExpression uri,
        AzureApiManagementBackendOptions? options = null,
        string? backendName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical backend name.
- `uri` (`ReferenceExpression`)
  The deferred URI of the backend service.
- `options` ([AzureApiManagementBackendOptions?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementbackendoptions.md)) `optional`
  The backend options.
- `backendName` (`string?`) `optional`
  The physical backend identifier in API Management. The Aspire resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementBackendResource>` -- A builder for the backend resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addbackendpool"></a>
<a id="addbackendpool-iresourcebuilder-azureapimanagementresource-string-string-string"></a>

## AddBackendPool(IResourceBuilder<AzureApiManagementResource>, string, string?, string?)

- Name: `AddBackendPool(IResourceBuilder<AzureApiManagementResource>, string, string?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementBackendPoolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L993-L1020)

Adds a reusable load-balancing pool to the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementBackendPoolResource> AddBackendPool(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        string? displayName = null,
        string? backendPoolName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
- `name` (`string`)
- `displayName` (`string?`) `optional`
- `backendPoolName` (`string?`) `optional`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addblobstoragebackend"></a>
<a id="addblobstoragebackend-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-azureblobstorageresource-string"></a>

## AddBlobStorageBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<AzureBlobStorageResource>, string?)

- Name: `AddBlobStorageBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<AzureBlobStorageResource>, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementBackendResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L964-L980)

Adds an Azure Blob Storage service as an API Management backend.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementBackendResource> AddBlobStorageBackend(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        IResourceBuilder<AzureBlobStorageResource> blobs,
        string? backendName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
- `name` (`string`)
- `blobs` (`IResourceBuilder<AzureBlobStorageResource>`)
- `backendName` (`string?`) `optional`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addfoundrybackend"></a>
<a id="addfoundrybackend-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-foundrydeploymentresource-string"></a>

## AddFoundryBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?)

- Name: `AddFoundryBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementBackendResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L930-L951)

Adds a Microsoft Foundry OpenAI deployment as an API Management backend.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementBackendResource> AddFoundryBackend(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        IResourceBuilder<FoundryDeploymentResource> deployment,
        string? backendName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
- `name` (`string`)
- `deployment` (`IResourceBuilder<FoundryDeploymentResource>`)
- `backendName` (`string?`) `optional`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addkeyvaultnamedvalue"></a>
<a id="addkeyvaultnamedvalue-iresourcebuilder-azureapimanagementresource-string-iazurekeyvaultsecretreference-string-string-string"></a>

## AddKeyVaultNamedValue(IResourceBuilder<AzureApiManagementResource>, string, IAzureKeyVaultSecretReference, string?, string?, string[]?)

- Name: `AddKeyVaultNamedValue(IResourceBuilder<AzureApiManagementResource>, string, IAzureKeyVaultSecretReference, string?, string?, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementNamedValueResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L562-L567)

Adds a Key Vault-backed named value to the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementNamedValueResource> AddKeyVaultNamedValue(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        IAzureKeyVaultSecretReference value,
        string? displayName = null,
        string? namedValueName = null,
        string[]? tags = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical named-value name.
- `value` (`IAzureKeyVaultSecretReference`)
  The Key Vault secret reference.
- `displayName` (`string?`) `optional`
  The name used to reference the value in policies. The resource name is used when omitted.
- `namedValueName` (`string?`) `optional`
  The physical named-value identifier in API Management. The resource name is used when omitted.
- `tags` (`string[]?`) `optional`
  Tags used to organize the named value.

## Returns

`IResourceBuilder<AzureApiManagementNamedValueResource>` -- A builder for the named-value resource.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot AppHosts pass the Key Vault resource and secret name separately.

<a id="addnamedvalue"></a>
<a id="addnamedvalue-iresourcebuilder-azureapimanagementresource-string-string-string-string-string"></a>

## AddNamedValue(IResourceBuilder<AzureApiManagementResource>, string, string, string?, string?, string[]?)

- Name: `AddNamedValue(IResourceBuilder<AzureApiManagementResource>, string, string, string?, string?, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementNamedValueResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L508-L510)

Adds a non-secret named value to the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementNamedValueResource> AddNamedValue(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        string value,
        string? displayName = null,
        string? namedValueName = null,
        string[]? tags = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical named-value name.
- `value` (`string`)
  The named value.
- `displayName` (`string?`) `optional`
  The name used to reference the value in policies. The resource name is used when omitted.
- `namedValueName` (`string?`) `optional`
  The physical named-value identifier in API Management. The resource name is used when omitted.
- `tags` (`string[]?`) `optional`
  Tags used to organize the named value.

## Returns

`IResourceBuilder<AzureApiManagementNamedValueResource>` -- A builder for the named-value resource.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/addApiManagementNamedValue`
- Generated method name override: `addNamedValue`

<a id="addopenaiapi"></a>
<a id="addopenaiapi-iresourcebuilder-azureapimanagementresource-string-string-string-bool-string"></a>

## AddOpenAIApi(IResourceBuilder<AzureApiManagementResource>, string, string, string?, bool, string?)

- Name: `AddOpenAIApi(IResourceBuilder<AzureApiManagementResource>, string, string, string?, bool, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L321-L330)

Adds an OpenAI-compatible API backed by an API Management load-balancing pool.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> AddOpenAIApi(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        string path,
        string? displayName = null,
        bool subscriptionRequired = true,
        string? apiName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical API name.
- `path` (`string`)
  The public path beneath the API Management gateway hostname.
- `displayName` (`string?`) `optional`
  The API display name. The resource name is used when omitted.
- `subscriptionRequired` (`bool`) `optional`
  Whether callers must provide an API Management subscription key. The default is `true`.
- `apiName` (`string?`) `optional`
  The physical API identifier in API Management. The Aspire resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- A builder for the API resource.

## Remarks

Create backends with [AzureApiManagementExtensions.AddAzureOpenAIBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<AzureOpenAIDeploymentResource>, string?)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#addazureopenaibackend-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-azureopenaideploymentresource-string) or [AzureApiManagementExtensions.AddFoundryBackend(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<FoundryDeploymentResource>, string?)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#addfoundrybackend-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-foundrydeploymentresource-string), compose them with [AzureApiManagementExtensions.AddBackendPool(IResourceBuilder<AzureApiManagementResource>, string, string?, string?)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#addbackendpool-iresourcebuilder-azureapimanagementresource-string-string-string), and attach the pool with [AzureApiManagementExtensions.WithBackend(IResourceBuilder<AzureApiManagementBackendPoolResource>, IResourceBuilder<AzureApiManagementBackendResource>, int, int)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withbackend-iresourcebuilder-azureapimanagementbackendpoolresource-iresourcebuilder-azureapimanagementbackendresource-int-int). Requests beneath `path` are appended to the selected backend URI.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addoperation"></a>
<a id="addoperation-iresourcebuilder-azureapimanagementapiresource-string-string-string-string-string"></a>

## AddOperation(IResourceBuilder<AzureApiManagementApiResource>, string, string, string, string?, string?)

- Name: `AddOperation(IResourceBuilder<AzureApiManagementApiResource>, string, string, string, string?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementOperationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L1226-L1285)

Adds an explicitly modeled operation to an API.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementOperationResource> AddOperation(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        string name,
        string method,
        string urlTemplate,
        string? displayName = null,
        string? operationName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical operation name.
- `method` (`string`)
  The HTTP method.
- `urlTemplate` (`string`)
  The URL template relative to the API path.
- `displayName` (`string?`) `optional`
  The operation display name. The resource name is used when omitted.
- `operationName` (`string?`) `optional`
  The physical operation identifier in API Management. The Aspire resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementOperationResource>` -- A builder for the operation resource.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` is null.
- `ArgumentException` -- Thrown when a required string is empty.
- `InvalidOperationException` -- Thrown when the operation identifier or route duplicates another operation or conflicts with a generated proxy route.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addpolicyfragment"></a>
<a id="addpolicyfragment-iresourcebuilder-azureapimanagementresource-string-string-string-string"></a>

## AddPolicyFragment(IResourceBuilder<AzureApiManagementResource>, string, string, string?, string?)

- Name: `AddPolicyFragment(IResourceBuilder<AzureApiManagementResource>, string, string, string?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementPolicyFragmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L610-L641)

Adds a reusable policy fragment to the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementPolicyFragmentResource> AddPolicyFragment(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        string policyXml,
        string? description = null,
        string? fragmentName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical policy-fragment name.
- `policyXml` (`string`)
  One or more well-formed APIM policy elements without a `fragment` envelope.
- `description` (`string?`) `optional`
  An optional description.
- `fragmentName` (`string?`) `optional`
  The physical policy-fragment identifier in API Management. The resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementPolicyFragmentResource>` -- A builder for the policy-fragment resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addproduct"></a>
<a id="addproduct-iresourcebuilder-azureapimanagementresource-string-string-azureapimanagementproductoptions-string"></a>

## AddProduct(IResourceBuilder<AzureApiManagementResource>, string, string, AzureApiManagementProductOptions?, string?)

- Name: `AddProduct(IResourceBuilder<AzureApiManagementResource>, string, string, AzureApiManagementProductOptions?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementProductResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L350-L403)

Adds a product to the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementProductResource> AddProduct(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        string displayName,
        AzureApiManagementProductOptions? options = null,
        string? productName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical product name.
- `displayName` (`string`)
  The product display name.
- `options` ([AzureApiManagementProductOptions?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementproductoptions.md)) `optional`
  The product options.
- `productName` (`string?`) `optional`
  The physical product identifier in API Management. The resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementProductResource>` -- A builder for the product resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addsecretnamedvalue"></a>
<a id="addsecretnamedvalue-iresourcebuilder-azureapimanagementresource-string-iresourcebuilder-parameterresource-string-string-string"></a>

## AddSecretNamedValue(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<ParameterResource>, string?, string?, string[]?)

- Name: `AddSecretNamedValue(IResourceBuilder<AzureApiManagementResource>, string, IResourceBuilder<ParameterResource>, string?, string?, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementNamedValueResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L532-L540)

Adds a secret parameter as a named value in the API Management service.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementNamedValueResource> AddSecretNamedValue(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string name,
        IResourceBuilder<ParameterResource> value,
        string? displayName = null,
        string? namedValueName = null,
        string[]? tags = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical named-value name.
- `value` (`IResourceBuilder<ParameterResource>`)
  The secret parameter containing the named value.
- `displayName` (`string?`) `optional`
  The name used to reference the value in policies. The resource name is used when omitted.
- `namedValueName` (`string?`) `optional`
  The physical named-value identifier in API Management. The resource name is used when omitted.
- `tags` (`string[]?`) `optional`
  Tags used to organize the named value.

## Returns

`IResourceBuilder<AzureApiManagementNamedValueResource>` -- A builder for the named-value resource.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/addApiManagementSecretNamedValue`
- Generated method name override: `addSecretNamedValue`

<a id="addsubscription"></a>
<a id="addsubscription-iresourcebuilder-azureapimanagementproductresource-string-string-azureapimanagementsubscriptionoptions-string"></a>

## AddSubscription(IResourceBuilder<AzureApiManagementProductResource>, string, string, AzureApiManagementSubscriptionOptions?, string?)

- Name: `AddSubscription(IResourceBuilder<AzureApiManagementProductResource>, string, string, AzureApiManagementSubscriptionOptions?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementSubscriptionResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L450-L486)

Adds a subscription scoped to an API Management product.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementSubscriptionResource> AddSubscription(
        this IResourceBuilder<AzureApiManagementProductResource> builder,
        string name,
        string displayName,
        AzureApiManagementSubscriptionOptions? options = null,
        string? subscriptionName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementProductResource>`)
  The API Management product resource builder.
- `name` (`string`)
  The globally unique Aspire resource name and default physical subscription name.
- `displayName` (`string`)
  The subscription display name.
- `options` ([AzureApiManagementSubscriptionOptions?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementsubscriptionoptions.md)) `optional`
  The subscription options.
- `subscriptionName` (`string?`) `optional`
  The physical subscription identifier in API Management. The resource name is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementSubscriptionResource>` -- A builder for the subscription resource.

## Remarks

API Management generates the primary and secondary subscription keys during deployment.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withapi"></a>
<a id="withapi-iresourcebuilder-azureapimanagementproductresource-iresourcebuilder-azureapimanagementapiresource"></a>

## WithApi(IResourceBuilder<AzureApiManagementProductResource>, IResourceBuilder<AzureApiManagementApiResource>)

- Name: `WithApi(IResourceBuilder<AzureApiManagementProductResource>, IResourceBuilder<AzureApiManagementApiResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementProductResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L417-L429)

Adds an API to an API Management product.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementProductResource> WithApi(
        this IResourceBuilder<AzureApiManagementProductResource> builder,
        IResourceBuilder<AzureApiManagementApiResource> api)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementProductResource>`)
  The API Management product resource builder.
- `api` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API to add to the product.

## Returns

`IResourceBuilder<AzureApiManagementProductResource>` -- The product resource builder.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withapplicationinsights"></a>
<a id="withapplicationinsights-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azureapplicationinsightsresource-azureapimanagementdiagnosticoptions"></a>

## WithApplicationInsights(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureApplicationInsightsResource>, AzureApiManagementDiagnosticOptions?)

- Name: `WithApplicationInsights(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureApplicationInsightsResource>, AzureApiManagementDiagnosticOptions?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Sends service-level API Management diagnostics to Application Insights.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithApplicationInsights(
        this IResourceBuilder<AzureApiManagementResource> builder,
        IResourceBuilder<AzureApplicationInsightsResource> applicationInsights,
        AzureApiManagementDiagnosticOptions? options = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `applicationInsights` (`IResourceBuilder<AzureApplicationInsightsResource>`)
  The Application Insights resource.
- `options` ([AzureApiManagementDiagnosticOptions?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementdiagnosticoptions.md)) `optional`
  The diagnostic options.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementServiceApplicationInsights`
- Generated method name override: `withApplicationInsights`

<a id="withapplicationinsights-iresourcebuilder-azureapimanagementapiresource-iresourcebuilder-azureapplicationinsightsresource-azureapimanagementdiagnosticoptions"></a>

## WithApplicationInsights(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApplicationInsightsResource>, AzureApiManagementDiagnosticOptions?)

- Name: `WithApplicationInsights(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApplicationInsightsResource>, AzureApiManagementDiagnosticOptions?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Sends API-level API Management diagnostics to Application Insights.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithApplicationInsights(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        IResourceBuilder<AzureApplicationInsightsResource> applicationInsights,
        AzureApiManagementDiagnosticOptions? options = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API Management API resource builder.
- `applicationInsights` (`IResourceBuilder<AzureApplicationInsightsResource>`)
  The Application Insights resource.
- `options` ([AzureApiManagementDiagnosticOptions?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementdiagnosticoptions.md)) `optional`
  The diagnostic options.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- The resource builder.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementApiApplicationInsights`
- Generated method name override: `withApplicationInsights`

<a id="withazureuserassignedidentity"></a>
<a id="withazureuserassignedidentity-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azureuserassignedidentityresource"></a>

## WithAzureUserAssignedIdentity(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)

- Name: `WithAzureUserAssignedIdentity(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L138-L155)

Configures the user-assigned managed identity used by API Management.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithAzureUserAssignedIdentity(
        this IResourceBuilder<AzureApiManagementResource> builder,
        IResourceBuilder<AzureUserAssignedIdentityResource> identityResourceBuilder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `identityResourceBuilder` (`IResourceBuilder<AzureUserAssignedIdentityResource>`)
  The user-assigned managed identity.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The Azure API Management resource builder.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `identityResourceBuilder` is null.

## Remarks

New services attach the supplied identity automatically instead of creating a default identity. For an existing service, the supplied identity must be configured as an existing resource and already attached to the service outside Aspire. Aspire does not change or verify the existing service's identity attachments. Backend and Key Vault permissions use the supplied identity.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withbackend"></a>
<a id="withbackend-iresourcebuilder-azureapimanagementbackendpoolresource-iresourcebuilder-azureapimanagementbackendresource-int-int"></a>

## WithBackend(IResourceBuilder<AzureApiManagementBackendPoolResource>, IResourceBuilder<AzureApiManagementBackendResource>, int, int)

- Name: `WithBackend(IResourceBuilder<AzureApiManagementBackendPoolResource>, IResourceBuilder<AzureApiManagementBackendResource>, int, int)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementBackendPoolResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L1033-L1069)

Adds a backend to a load-balancing pool.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementBackendPoolResource> WithBackend(
        this IResourceBuilder<AzureApiManagementBackendPoolResource> builder,
        IResourceBuilder<AzureApiManagementBackendResource> backend,
        int priority = 1,
        int weight = 1)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementBackendPoolResource>`)
- `backend` (`IResourceBuilder<AzureApiManagementBackendResource>`)
- `priority` (`int`) `optional`
- `weight` (`int`) `optional`

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/addBackendPoolMember`

<a id="withbackend-iresourcebuilder-azureapimanagementapiresource-iresourcebuilder-azureapimanagementbackendresource"></a>

## WithBackend(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApiManagementBackendResource>)

- Name: `WithBackend(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApiManagementBackendResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Configures an API to route requests to a backend.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithBackend(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        IResourceBuilder<AzureApiManagementBackendResource> backend)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
- `backend` (`IResourceBuilder<AzureApiManagementBackendResource>`)

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiBackend`

<a id="withbackend-iresourcebuilder-azureapimanagementapiresource-iresourcebuilder-azureapimanagementbackendpoolresource"></a>

## WithBackend(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApiManagementBackendPoolResource>)

- Name: `WithBackend(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApiManagementBackendPoolResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Configures an API to route requests to a backend pool.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithBackend(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        IResourceBuilder<AzureApiManagementBackendPoolResource> backend)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
- `backend` (`IResourceBuilder<AzureApiManagementBackendPoolResource>`)

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiBackendPool`

<a id="withclassicvirtualnetwork"></a>
<a id="withclassicvirtualnetwork-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azuresubnetresource-azureapimanagementvirtualnetworkmode"></a>

## WithClassicVirtualNetwork(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>, AzureApiManagementVirtualNetworkMode)

- Name: `WithClassicVirtualNetwork(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>, AzureApiManagementVirtualNetworkMode)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L1431-L1455)

Injects a classic Developer or Premium API Management service into a virtual network subnet.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithClassicVirtualNetwork(
        this IResourceBuilder<AzureApiManagementResource> builder,
        IResourceBuilder<AzureSubnetResource> subnet,
        AzureApiManagementVirtualNetworkMode mode)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `subnet` (`IResourceBuilder<AzureSubnetResource>`)
  The subnet resource. Classic APIM injection requires an undelegated subnet with an NSG.
- `mode` ([AzureApiManagementVirtualNetworkMode](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementvirtualnetworkmode.md))
  Whether the APIM endpoints are externally or internally accessible.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## Exceptions

- `InvalidOperationException` -- Thrown when the selected SKU does not support classic VNet injection or the subnet is delegated.

## Remarks

This API models classic VNet injection only. Standard v2 outbound integration and Premium v2 injection have different subnet delegations and lifecycle constraints. Use [AzureApiManagementExtensions.WithVirtualNetworkIntegration(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withvirtualnetworkintegration-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azuresubnetresource) for Standard v2 outbound integration or [AzureApiManagementExtensions.WithVirtualNetworkInjection(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withvirtualnetworkinjection-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azuresubnetresource) for Premium v2 injection. See [APIM virtual networking](https://learn.microsoft.com/azure/api-management/virtual-network-concepts).

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withcustomdomain"></a>
<a id="withcustomdomain-iresourcebuilder-azureapimanagementresource-string-iazurekeyvaultsecretreference-azureapimanagementhostnametype-bool-bool"></a>

## WithCustomDomain(IResourceBuilder<AzureApiManagementResource>, string, IAzureKeyVaultSecretReference, AzureApiManagementHostnameType, bool, bool)

- Name: `WithCustomDomain(IResourceBuilder<AzureApiManagementResource>, string, IAzureKeyVaultSecretReference, AzureApiManagementHostnameType, bool, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L763-L819)

Configures a custom hostname using a certificate stored in Azure Key Vault.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithCustomDomain(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string hostname,
        IAzureKeyVaultSecretReference certificate,
        AzureApiManagementHostnameType type = AzureApiManagementHostnameType.Proxy,
        bool defaultSslBinding = false,
        bool negotiateClientCertificate = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `hostname` (`string`)
  The fully qualified custom hostname.
- `certificate` (`IAzureKeyVaultSecretReference`)
  The Key Vault secret containing a PFX certificate.
- `type` ([AzureApiManagementHostnameType](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementhostnametype.md)) `optional`
  The API Management endpoint to configure.
- `defaultSslBinding` (`bool`) `optional`
  Whether this certificate is the default SNI fallback. This is valid only for gateway hostnames.
- `negotiateClientCertificate` (`bool`) `optional`
  Whether the endpoint negotiates client certificates.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot AppHosts pass the Key Vault resource and secret name separately.

<a id="withinboundpolicy"></a>
<a id="withinboundpolicy-iresourcebuilder-azureapimanagementresource-string"></a>

## WithInboundPolicy(IResourceBuilder<AzureApiManagementResource>, string)

- Name: `WithInboundPolicy(IResourceBuilder<AzureApiManagementResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Appends an XML policy statement to the service-level inbound policy section.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithInboundPolicy(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string policyXml)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `policyXml` (`string`)
  One or more well-formed APIM policy elements without a `policies` envelope.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## Exceptions

- `ArgumentException` -- Thrown when `policyXml` is empty or is not a valid XML fragment.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementServiceInboundPolicy`
- Generated method name override: `withInboundPolicy`

<a id="withinboundpolicy-iresourcebuilder-azureapimanagementapiresource-string"></a>

## WithInboundPolicy(IResourceBuilder<AzureApiManagementApiResource>, string)

- Name: `WithInboundPolicy(IResourceBuilder<AzureApiManagementApiResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Appends an XML policy statement to the API-level inbound policy section.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithInboundPolicy(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        string policyXml)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API resource builder.
- `policyXml` (`string`)
  One or more well-formed APIM policy elements without a `policies` envelope.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- The resource builder.

## Exceptions

- `ArgumentException` -- Thrown when `policyXml` is empty or is not a valid XML fragment.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementApiInboundPolicy`
- Generated method name override: `withInboundPolicy`

<a id="withinboundpolicy-iresourcebuilder-azureapimanagementoperationresource-string"></a>

## WithInboundPolicy(IResourceBuilder<AzureApiManagementOperationResource>, string)

- Name: `WithInboundPolicy(IResourceBuilder<AzureApiManagementOperationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementOperationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Appends an XML policy statement to the operation-level inbound policy section.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementOperationResource> WithInboundPolicy(
        this IResourceBuilder<AzureApiManagementOperationResource> builder,
        string policyXml)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementOperationResource>`)
  The operation resource builder.
- `policyXml` (`string`)
  One or more well-formed APIM policy elements without a `policies` envelope.

## Returns

`IResourceBuilder<AzureApiManagementOperationResource>` -- The resource builder.

## Exceptions

- `ArgumentException` -- Thrown when `policyXml` is empty or is not a valid XML fragment.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementOperationInboundPolicy`
- Generated method name override: `withInboundPolicy`

<a id="withinboundpolicyfragment"></a>
<a id="withinboundpolicyfragment-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azureapimanagementpolicyfragmentresource"></a>

## WithInboundPolicyFragment(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureApiManagementPolicyFragmentResource>)

- Name: `WithInboundPolicyFragment(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureApiManagementPolicyFragmentResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Includes a policy fragment in the service-level inbound policy.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithInboundPolicyFragment(
        this IResourceBuilder<AzureApiManagementResource> builder,
        IResourceBuilder<AzureApiManagementPolicyFragmentResource> fragment)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `fragment` (`IResourceBuilder<AzureApiManagementPolicyFragmentResource>`)
  The policy fragment to include.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementServiceInboundPolicyFragment`
- Generated method name override: `withInboundPolicyFragment`

<a id="withinboundpolicyfragment-iresourcebuilder-azureapimanagementapiresource-iresourcebuilder-azureapimanagementpolicyfragmentresource"></a>

## WithInboundPolicyFragment(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApiManagementPolicyFragmentResource>)

- Name: `WithInboundPolicyFragment(IResourceBuilder<AzureApiManagementApiResource>, IResourceBuilder<AzureApiManagementPolicyFragmentResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Includes a policy fragment in the API-level inbound policy.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithInboundPolicyFragment(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        IResourceBuilder<AzureApiManagementPolicyFragmentResource> fragment)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API Management API resource builder.
- `fragment` (`IResourceBuilder<AzureApiManagementPolicyFragmentResource>`)
  The policy fragment to include.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- The resource builder.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementApiInboundPolicyFragment`
- Generated method name override: `withInboundPolicyFragment`

<a id="withinboundpolicyfragment-iresourcebuilder-azureapimanagementoperationresource-iresourcebuilder-azureapimanagementpolicyfragmentresource"></a>

## WithInboundPolicyFragment(IResourceBuilder<AzureApiManagementOperationResource>, IResourceBuilder<AzureApiManagementPolicyFragmentResource>)

- Name: `WithInboundPolicyFragment(IResourceBuilder<AzureApiManagementOperationResource>, IResourceBuilder<AzureApiManagementPolicyFragmentResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementOperationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Includes a policy fragment in the operation-level inbound policy.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementOperationResource> WithInboundPolicyFragment(
        this IResourceBuilder<AzureApiManagementOperationResource> builder,
        IResourceBuilder<AzureApiManagementPolicyFragmentResource> fragment)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementOperationResource>`)
  The API Management operation resource builder.
- `fragment` (`IResourceBuilder<AzureApiManagementPolicyFragmentResource>`)
  The policy fragment to include.

## Returns

`IResourceBuilder<AzureApiManagementOperationResource>` -- The resource builder.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementOperationInboundPolicyFragment`
- Generated method name override: `withInboundPolicyFragment`

<a id="withopenapidocument"></a>
<a id="withopenapidocument-iresourcebuilder-azureapimanagementapiresource-string-azureapimanagementopenapiformat"></a>

## WithOpenApiDocument(IResourceBuilder<AzureApiManagementApiResource>, string, AzureApiManagementOpenApiFormat?)

- Name: `WithOpenApiDocument(IResourceBuilder<AzureApiManagementApiResource>, string, AzureApiManagementOpenApiFormat?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L242-L249)

Imports an OpenAPI document from a file into an API.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithOpenApiDocument(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        string documentPath,
        AzureApiManagementOpenApiFormat? format = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API Management API resource builder.
- `documentPath` (`string`)
  The document path, relative to the AppHost directory when not absolute.
- `format` ([AzureApiManagementOpenApiFormat?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementopenapiformat.md)) `optional`
  The document format. The file extension is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- The API Management API resource builder.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` is null.
- `ArgumentException` -- Thrown when `documentPath` is empty or its extension cannot determine the format.
- `InvalidOperationException` -- Thrown when a different OpenAPI source is already configured.

## Remarks

The document is read when generating infrastructure for publish or deploy, never during run mode. It must exist and contain non-whitespace content by the time infrastructure is generated. An API can have only one OpenAPI source: either a document file or an endpoint. Repeating the same source configuration is allowed; configuring a different source throws.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withopenapiendpoint"></a>
<a id="withopenapiendpoint-iresourcebuilder-azureapimanagementapiresource-string-string-azureapimanagementopenapiformat"></a>

## WithOpenApiEndpoint(IResourceBuilder<AzureApiManagementApiResource>, string, string?, AzureApiManagementOpenApiFormat?)

- Name: `WithOpenApiEndpoint(IResourceBuilder<AzureApiManagementApiResource>, string, string?, AzureApiManagementOpenApiFormat?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L276-L294)

Imports an OpenAPI document exposed by the API's target compute resource.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithOpenApiEndpoint(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        string documentPath = "/openapi/v1.json",
        string? endpointName = null,
        AzureApiManagementOpenApiFormat? format = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API Management API resource builder.
- `documentPath` (`string`) `optional`
  The absolute path of the OpenAPI endpoint, such as `/openapi/v1.json`.
- `endpointName` (`string?`) `optional`
  The target endpoint name. An external HTTP or HTTPS endpoint is selected when omitted.
- `format` ([AzureApiManagementOpenApiFormat?](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementopenapiformat.md)) `optional`
  The document format. The endpoint path extension is used when omitted.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- The API Management API resource builder.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` is null.
- `ArgumentException` -- Thrown when `documentPath` is empty or is not an absolute path.
- `InvalidOperationException` -- Thrown when a different OpenAPI source is already configured, or the API has no target compute resource or no suitable external endpoint.

## Remarks

Azure API Management retrieves linked documents through its control plane, so the selected endpoint must be externally reachable during deployment. Use [AzureApiManagementExtensions.WithOpenApiDocument(IResourceBuilder<AzureApiManagementApiResource>, string, AzureApiManagementOpenApiFormat?)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withopenapidocument-iresourcebuilder-azureapimanagementapiresource-string-azureapimanagementopenapiformat) for private backends. An API can have only one OpenAPI source: either a document file or an endpoint. Repeating the same source configuration is allowed; configuring a different source throws.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withpolicy"></a>
<a id="withpolicy-iresourcebuilder-azureapimanagementresource-string"></a>

## WithPolicy(IResourceBuilder<AzureApiManagementResource>, string)

- Name: `WithPolicy(IResourceBuilder<AzureApiManagementResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Replaces the complete service-level policy document.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithPolicy(
        this IResourceBuilder<AzureApiManagementResource> builder,
        string policyXml)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `policyXml` (`string`)
  A complete APIM `policies` XML document.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## Exceptions

- `ArgumentException` -- Thrown when `policyXml` is not a complete policy document.

## Remarks

APIM policy updates replace the complete policy document at a scope. To prevent silently dropping policy fragments, this method cannot be combined with [AzureApiManagementExtensions.WithInboundPolicy(IResourceBuilder<AzureApiManagementResource>, string)](/reference/api/csharp/aspire.hosting.azure.apimanagement/azureapimanagementextensions/methods.md#withinboundpolicy-iresourcebuilder-azureapimanagementresource-string) at the same scope.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementServicePolicy`
- Generated method name override: `withPolicy`

<a id="withpolicy-iresourcebuilder-azureapimanagementapiresource-string"></a>

## WithPolicy(IResourceBuilder<AzureApiManagementApiResource>, string)

- Name: `WithPolicy(IResourceBuilder<AzureApiManagementApiResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementApiResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Replaces the complete API-level policy document.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementApiResource> WithPolicy(
        this IResourceBuilder<AzureApiManagementApiResource> builder,
        string policyXml)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementApiResource>`)
  The API resource builder.
- `policyXml` (`string`)
  A complete APIM `policies` XML document.

## Returns

`IResourceBuilder<AzureApiManagementApiResource>` -- The resource builder.

## Exceptions

- `ArgumentException` -- Thrown when `policyXml` is not a complete policy document.

## Remarks

Replacing the API policy also replaces the generated backend-routing policy. The supplied document must configure backend routing when the API should continue forwarding requests.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementApiPolicy`
- Generated method name override: `withPolicy`

<a id="withpolicy-iresourcebuilder-azureapimanagementoperationresource-string"></a>

## WithPolicy(IResourceBuilder<AzureApiManagementOperationResource>, string)

- Name: `WithPolicy(IResourceBuilder<AzureApiManagementOperationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementOperationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs)

Replaces the complete operation-level policy document.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementOperationResource> WithPolicy(
        this IResourceBuilder<AzureApiManagementOperationResource> builder,
        string policyXml)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementOperationResource>`)
  The operation resource builder.
- `policyXml` (`string`)
  A complete APIM `policies` XML document.

## Returns

`IResourceBuilder<AzureApiManagementOperationResource>` -- The resource builder.

## Exceptions

- `ArgumentException` -- Thrown when `policyXml` is not a complete policy document.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.ApiManagement/withApiManagementOperationPolicy`
- Generated method name override: `withPolicy`

<a id="withvirtualnetworkinjection"></a>
<a id="withvirtualnetworkinjection-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azuresubnetresource"></a>

## WithVirtualNetworkInjection(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>)

- Name: `WithVirtualNetworkInjection(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L1529-L1555)

Injects a Premium v2 API Management service into a virtual network for private inbound and outbound access.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithVirtualNetworkInjection(
        this IResourceBuilder<AzureApiManagementResource> builder,
        IResourceBuilder<AzureSubnetResource> subnet)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `subnet` (`IResourceBuilder<AzureSubnetResource>`)
  A dedicated subnet for API Management virtual network injection.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## Exceptions

- `InvalidOperationException` -- Thrown when the selected SKU is not Premium v2, the subnet has a conflicting delegation, or the subnet is already used by another API Management service, or its NSG cannot accommodate the required Key Vault allow rule ahead of outbound deny rules.

## Remarks

The subnet is delegated to `Microsoft.Web/hostingEnvironments`. Premium v2 injection can only be selected when the service is created and cannot later be changed to virtual network integration. See [Premium v2 virtual network injection](https://learn.microsoft.com/azure/api-management/inject-vnet-v2).

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withvirtualnetworkintegration"></a>
<a id="withvirtualnetworkintegration-iresourcebuilder-azureapimanagementresource-iresourcebuilder-azuresubnetresource"></a>

## WithVirtualNetworkIntegration(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>)

- Name: `WithVirtualNetworkIntegration(IResourceBuilder<AzureApiManagementResource>, IResourceBuilder<AzureSubnetResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApiManagementResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.ApiManagement/AzureApiManagementExtensions.cs#L1479-L1505)

Integrates a Standard v2 or Premium v2 API Management service with a virtual network for outbound access.

```csharp
public static class AzureApiManagementExtensions
{
    public static IResourceBuilder<AzureApiManagementResource> WithVirtualNetworkIntegration(
        this IResourceBuilder<AzureApiManagementResource> builder,
        IResourceBuilder<AzureSubnetResource> subnet)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApiManagementResource>`)
  The Azure API Management resource builder.
- `subnet` (`IResourceBuilder<AzureSubnetResource>`)
  A dedicated subnet for API Management virtual network integration.

## Returns

`IResourceBuilder<AzureApiManagementResource>` -- The resource builder.

## Exceptions

- `InvalidOperationException` -- Thrown when the selected SKU does not support v2 virtual network integration, the subnet has a conflicting delegation, the subnet is already used by another API Management service, or its NSG cannot accommodate the required Key Vault allow rule ahead of outbound deny rules.

## Remarks

The subnet is delegated to `Microsoft.Web/serverFarms`. The APIM gateway remains publicly accessible, while backend traffic can reach resources in the virtual network. See [APIM outbound virtual network integration](https://learn.microsoft.com/azure/api-management/integrate-vnet-outbound).

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
