# StableDiffusionCppResourceBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.StableDiffusionCpp](/reference/api/csharp/communitytoolkit.aspire.hosting.stablediffusioncpp.md)
- Type: [StableDiffusionCppResourceBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.stablediffusioncpp/stablediffusioncppresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `6`

Provides extension methods for adding stable-diffusion.cpp resources to an `Hosting.IDistributedApplicationBuilder`.

<a id="addhuggingfacemodel"></a>
<a id="addhuggingfacemodel-iresourcebuilder-stablediffusioncppresource-string-string-string"></a>

## AddHuggingFaceModel(IResourceBuilder<StableDiffusionCppResource>, string, string, string)

- Name: `AddHuggingFaceModel(IResourceBuilder<StableDiffusionCppResource>, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StableDiffusionCppModelResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1/src/CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/StableDiffusionCppResourceBuilderExtensions.cs#L154-L166)

Adds a Hugging Face model that is downloaded before the container starts.

```csharp
public static class StableDiffusionCppResourceBuilderExtensions
{
    public static IResourceBuilder<StableDiffusionCppModelResource> AddHuggingFaceModel(
        this IResourceBuilder<StableDiffusionCppResource> builder,
        string repository,
        string fileName,
        string revision = "main")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StableDiffusionCppResource>`)
  The stable-diffusion.cpp resource builder.
- `repository` (`string`)
  The Hugging Face repository identifier.
- `fileName` (`string`)
  The model file path within the repository.
- `revision` (`string`) `optional`
  The repository revision. Defaults to `main`.

## Returns

`IResourceBuilder<StableDiffusionCppModelResource>` -- A builder for the child model resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addhuggingfacemodel-iresourcebuilder-stablediffusioncppresource-string-string-string-string"></a>

## AddHuggingFaceModel(IResourceBuilder<StableDiffusionCppResource>, string, string, string, string)

- Name: `AddHuggingFaceModel(IResourceBuilder<StableDiffusionCppResource>, string, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StableDiffusionCppModelResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1/src/CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/StableDiffusionCppResourceBuilderExtensions.cs#L186-L208)

Adds a named Hugging Face model that is downloaded before the container starts.

```csharp
public static class StableDiffusionCppResourceBuilderExtensions
{
    public static IResourceBuilder<StableDiffusionCppModelResource> AddHuggingFaceModel(
        this IResourceBuilder<StableDiffusionCppResource> builder,
        string name,
        string repository,
        string fileName,
        string revision = "main")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StableDiffusionCppResource>`)
  The stable-diffusion.cpp resource builder.
- `name` (`string`)
  The child model resource name.
- `repository` (`string`)
  The Hugging Face repository identifier.
- `fileName` (`string`)
  The model file path within the repository.
- `revision` (`string`) `optional`
  The repository revision. Defaults to `main`.

## Returns

`IResourceBuilder<StableDiffusionCppModelResource>` -- A builder for the child model resource.

## ATS metadata

### ATS export

- Capability ID: `CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/addNamedHuggingFaceModel`

<a id="addstablediffusioncpp"></a>
<a id="addstablediffusioncpp-idistributedapplicationbuilder-string-stablediffusioncppimagevariant-int-string"></a>

## AddStableDiffusionCpp(IDistributedApplicationBuilder, string, StableDiffusionCppImageVariant, int?, string?)

- Name: `AddStableDiffusionCpp(IDistributedApplicationBuilder, string, StableDiffusionCppImageVariant, int?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StableDiffusionCppResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1/src/CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/StableDiffusionCppResourceBuilderExtensions.cs#L32-L74)

Adds a stable-diffusion.cpp container resource using an official image.

```csharp
public static class StableDiffusionCppResourceBuilderExtensions
{
    public static IResourceBuilder<StableDiffusionCppResource> AddStableDiffusionCpp(
        this IDistributedApplicationBuilder builder,
        string name,
        StableDiffusionCppImageVariant imageVariant = StableDiffusionCppImageVariant.Cuda,
        int? port = null,
        string? modelsDirectory = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The distributed application builder.
- `name` (`string`)
  The resource name.
- `imageVariant` ([StableDiffusionCppImageVariant](/reference/api/csharp/communitytoolkit.aspire.hosting.stablediffusioncpp/stablediffusioncppimagevariant.md)) `optional`
  The official image variant to use.
- `port` (`int?`) `optional`
  An optional host port. Aspire assigns one when omitted.
- `modelsDirectory` (`string?`) `optional`
  An optional host directory used for models. Defaults to `.stable-diffusion-cpp/{name}/models` under the AppHost directory.

## Returns

`IResourceBuilder<StableDiffusionCppResource>` -- A builder for the stable-diffusion.cpp resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withgpusupport"></a>
<a id="withgpusupport-iresourcebuilder-stablediffusioncppresource"></a>

## WithGPUSupport(IResourceBuilder<StableDiffusionCppResource>)

- Name: `WithGPUSupport(IResourceBuilder<StableDiffusionCppResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StableDiffusionCppResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1/src/CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/StableDiffusionCppResourceBuilderExtensions.cs#L86-L105)

Adds the container runtime arguments required by the selected GPU backend.

```csharp
public static class StableDiffusionCppResourceBuilderExtensions
{
    public static IResourceBuilder<StableDiffusionCppResource> WithGPUSupport(
        this IResourceBuilder<StableDiffusionCppResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StableDiffusionCppResource>`)
  The stable-diffusion.cpp resource builder.

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withhuggingfacetoken"></a>
<a id="withhuggingfacetoken-iresourcebuilder-stablediffusioncppresource-iresourcebuilder-parameterresource"></a>

## WithHuggingFaceToken(IResourceBuilder<StableDiffusionCppResource>, IResourceBuilder<ParameterResource>)

- Name: `WithHuggingFaceToken(IResourceBuilder<StableDiffusionCppResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StableDiffusionCppResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1/src/CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/StableDiffusionCppResourceBuilderExtensions.cs#L132-L136)

Supplies a Hugging Face access token for gated or private repositories.

```csharp
public static class StableDiffusionCppResourceBuilderExtensions
{
    public static IResourceBuilder<StableDiffusionCppResource> WithHuggingFaceToken(
        this IResourceBuilder<StableDiffusionCppResource> builder,
        IResourceBuilder<ParameterResource> token)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StableDiffusionCppResource>`)
  The stable-diffusion.cpp resource builder.
- `token` (`IResourceBuilder<ParameterResource>`)
  A secret parameter containing the Hugging Face token.

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withvaetiling"></a>
<a id="withvaetiling-iresourcebuilder-stablediffusioncppresource"></a>

## WithVaeTiling(IResourceBuilder<StableDiffusionCppResource>)

- Name: `WithVaeTiling(IResourceBuilder<StableDiffusionCppResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<StableDiffusionCppResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1/src/CommunityToolkit.Aspire.Hosting.StableDiffusionCpp/StableDiffusionCppResourceBuilderExtensions.cs#L117-L118)

Processes VAE images in tiles to reduce peak memory usage during image decoding.

```csharp
public static class StableDiffusionCppResourceBuilderExtensions
{
    public static IResourceBuilder<StableDiffusionCppResource> WithVaeTiling(
        this IResourceBuilder<StableDiffusionCppResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<StableDiffusionCppResource>`)
  The stable-diffusion.cpp resource builder.

## Returns

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

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
