Skip to content
DocsTry Aspire
DocsTry

GitHubModelsExtensions Methods

ClassMethods4 members
Provides extension methods for adding GitHub Models resources to the application model.
AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>)Section titled AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<GitHubModelResource>
Adds a GitHub Model resource to the application model.
public static class GitHubModelsExtensions
{
public static IResourceBuilder<GitHubModelResource> AddGitHubModel(
this IDistributedApplicationBuilder builder,
string name,
string model,
IResourceBuilder<ParameterResource>? organization = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
modelstringThe model name to use with GitHub Models.
organizationIResourceBuilder<ParameterResource>optionalThe organization login associated with the organization to which the request is to be attributed.
IResourceBuilder<GitHubModelResource>A reference to the ApplicationModel.IResourceBuilder`1.
AddGitHubModel(IDistributedApplicationBuilder, string, GitHubModel, IResourceBuilder<ParameterResource>)Section titled AddGitHubModel(IDistributedApplicationBuilder, string, GitHubModel, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<GitHubModelResource>
Adds a GitHub Model resource to the application model using a GitHubModel.
public static class GitHubModelsExtensions
{
public static IResourceBuilder<GitHubModelResource> AddGitHubModel(
this IDistributedApplicationBuilder builder,
string name,
GitHubModel model,
IResourceBuilder<ParameterResource>? organization = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
modelGitHubModelThe model descriptor, using the GitHubModel class like so:
builder.AddGitHubModel(
name: "chat",
model: GitHubModel.Microsoft.Phi3MediumInstruct)
organizationIResourceBuilder<ParameterResource>optionalThe organization login associated with the organization to which the request is to be attributed.
IResourceBuilder<GitHubModelResource>A reference to the ApplicationModel.IResourceBuilder`1.

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:
var builder = DistributedApplication.CreateBuilder(args);
var githubModel = builder.AddGitHubModel(
"chat",
GitHubModel.Microsoft.Phi3MediumInstruct);
WithApiKey(IResourceBuilder<GitHubModelResource>, IResourceBuilder<ParameterResource>)Section titled WithApiKey(IResourceBuilder<GitHubModelResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<GitHubModelResource>
Configures the API key for the GitHub Model resource from a parameter.
public static class GitHubModelsExtensions
{
public static IResourceBuilder<GitHubModelResource> WithApiKey(
this IResourceBuilder<GitHubModelResource> builder,
IResourceBuilder<ParameterResource> apiKey)
{
// ...
}
}
builderIResourceBuilder<GitHubModelResource>The resource builder.
apiKeyIResourceBuilder<ParameterResource>The API key parameter.
IResourceBuilder<GitHubModelResource>The resource builder.
ArgumentExceptionThrown when the provided parameter is not marked as secret.
WithHealthCheck(IResourceBuilder<GitHubModelResource>)Section titled WithHealthCheck(IResourceBuilder<GitHubModelResource>)extensionIResourceBuilder<GitHubModelResource>
Adds a health check to the GitHub Model resource.
public static class GitHubModelsExtensions
{
public static IResourceBuilder<GitHubModelResource> WithHealthCheck(
this IResourceBuilder<GitHubModelResource> builder)
{
// ...
}
}
builderIResourceBuilder<GitHubModelResource>The resource builder.
IResourceBuilder<GitHubModelResource>The resource builder.

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.