# GitHubModelsExtensions Methods

- Package: [Aspire.Hosting.GitHub.Models](/reference/api/csharp/aspire.hosting.github.models.md)
- Type: [GitHubModelsExtensions](/reference/api/csharp/aspire.hosting.github.models/githubmodelsextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for adding GitHub Models resources to the application model.

## AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>)

- Name: `AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<GitHubModelResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.GitHub.Models/GitHubModelsExtensions.cs)

Adds a GitHub Model resource to the application model.

```csharp
public static class GitHubModelsExtensions
{
    public static IResourceBuilder<GitHubModelResource> AddGitHubModel(
        this IDistributedApplicationBuilder builder,
        string name,
        string model,
        IResourceBuilder<ParameterResource>? organization = null)
    {
        // ...
    }
}
```

## 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.
- `model` (`string`)
  The model name to use with GitHub Models.
- `organization` (`IResourceBuilder<ParameterResource>`) `optional`
  The organization login associated with the organization to which the request is to be attributed.

## Returns

`IResourceBuilder<GitHubModelResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddGitHubModel(IDistributedApplicationBuilder, string, GitHubModel, IResourceBuilder<ParameterResource>)

- Name: `AddGitHubModel(IDistributedApplicationBuilder, string, GitHubModel, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<GitHubModelResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.GitHub.Models/GitHubModelsExtensions.cs)

Adds a GitHub Model resource to the application model using a [GitHubModel](/reference/api/csharp/aspire.hosting.github.models/githubmodel.md).

```csharp
public static class GitHubModelsExtensions
{
    public static IResourceBuilder<GitHubModelResource> AddGitHubModel(
        this IDistributedApplicationBuilder builder,
        string name,
        GitHubModel model,
        IResourceBuilder<ParameterResource>? organization = null)
    {
        // ...
    }
}
```

## 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.
- `model` ([GitHubModel](/reference/api/csharp/aspire.hosting.github.models/githubmodel.md))
  The model descriptor, using the [GitHubModel](/reference/api/csharp/aspire.hosting.github.models/githubmodel.md) class like so:

  ```csharp
  builder.AddGitHubModel(name: "chat", model: GitHubModel.Microsoft.Phi3MediumInstruct)
  ```
- `organization` (`IResourceBuilder<ParameterResource>`) `optional`
  The organization login associated with the organization to which the request is to be attributed.

## Returns

`IResourceBuilder<GitHubModelResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload is not available in polyglot app hosts. Use the string-based overload instead.

Create a GitHub Model resource for the Microsoft Phi-3 Medium Instruct model:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var githubModel = builder.AddGitHubModel("chat", GitHubModel.Microsoft.Phi3MediumInstruct);
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithApiKey(IResourceBuilder<GitHubModelResource>, IResourceBuilder<ParameterResource>)

- Name: `WithApiKey(IResourceBuilder<GitHubModelResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<GitHubModelResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.GitHub.Models/GitHubModelsExtensions.cs#L151-L167)

Configures the API key for the GitHub Model resource from a parameter.

```csharp
public static class GitHubModelsExtensions
{
    public static IResourceBuilder<GitHubModelResource> WithApiKey(
        this IResourceBuilder<GitHubModelResource> builder,
        IResourceBuilder<ParameterResource> apiKey)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<GitHubModelResource>`)
  The resource builder.
- `apiKey` (`IResourceBuilder<ParameterResource>`)
  The API key parameter.

## Returns

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

## Exceptions

- `ArgumentException` -- Thrown when the provided parameter is not marked as secret.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHealthCheck(IResourceBuilder<GitHubModelResource>)

- Name: `WithHealthCheck(IResourceBuilder<GitHubModelResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<GitHubModelResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.GitHub.Models/GitHubModelsExtensions.cs#L195-L229)

Adds a health check to the GitHub Model resource.

```csharp
public static class GitHubModelsExtensions
{
    public static IResourceBuilder<GitHubModelResource> WithHealthCheck(
        this IResourceBuilder<GitHubModelResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<GitHubModelResource>`)
  The resource builder.

## Returns

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

## Remarks

This method adds a health check that verifies the GitHub Models endpoint is accessible, the API key is valid, and the specified model is available. The health check will:

- Return `HealthStatus.Healthy` when the endpoint returns HTTP 200
- Return `HealthStatus.Unhealthy` with details when the API key is invalid (HTTP 401)
- Return `HealthStatus.Unhealthy` with error details when the model is unknown (HTTP 404)

Because health checks are included in the rate limit of the GitHub Models API, it is recommended to use this health check sparingly, such as when you are having issues understanding the reason the model is not working as expected. Furthermore, the health check will run a single time per application instance.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
