Zum Inhalt springen
Docs Try Aspire
Docs Try

Set up GitHub Models in the AppHost

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

GitHub logo

This article is the reference for the Aspire GitHub Models hosting integration. It enumerates the AppHost APIs — with examples for both AppHost.cs and apphost.ts — that you use to model GitHub Model resources in your AppHost project.

If you’re new to the GitHub Models integration, start with the Get started with GitHub Models integrations guide. For how consuming apps read the connection information this page exposes, see Connect to GitHub Models.

To start building an Aspire app that uses GitHub Models, install the 📦 Aspire.Hosting.GitHub.Models NuGet package:

Terminal
aspire add github-models

Learn more about aspire add in the command reference.

Or, choose a manual installation approach:

C# — AppHost.cs
#:package Aspire.Hosting.GitHub.Models@*
XML — AppHost.csproj
<PackageReference Include="Aspire.Hosting.GitHub.Models" Version="*" />

Once you’ve installed the hosting integration in your AppHost project, you can add a GitHub Model resource:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var chat = builder.AddGitHubModel("chat", GitHubModel.OpenAI.OpenAIGpt4oMini);
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(chat);
// After adding all resources, run the app...
  1. Calling AddGitHubModel (or addGitHubModel) creates a GitHubModelResource. It registers a secret parameter for the API key that defaults to the GITHUB_TOKEN environment variable.

  2. The model identifier selects which GitHub-hosted model to target. In C#, use the strongly-typed GitHubModel constants grouped by publisher; in TypeScript, use the GitHubModelName enum.

  3. The AppHost reference call configures a connection in the consuming project named after the resource (for example, chat in the preceding example).

If you prefer to specify the model by its raw string identifier rather than a constant, use AddGitHubModel (C#) with the string overload or addGitHubModelById (TypeScript):

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var chat = builder.AddGitHubModel("chat", "openai/gpt-4o-mini");
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(chat);
// After adding all resources, run the app...

Calling AddGitHubModel("chat", ...) (or addGitHubModel("chat", ...)) automatically creates a secret parameter named chat-gh-apikey. Aspire resolves its value in this order:

  1. The Parameters:chat-gh-apikey configuration key (user secrets, appsettings.*, or environment variables).
  2. The GITHUB_TOKEN environment variable.

If neither source provides a value, startup throws an exception. In Codespaces and GitHub Actions, GITHUB_TOKEN is populated automatically. For local development, provide a fine-grained personal access token with models: read scope via user secrets:

Terminal
aspire secret set Parameters:chat-gh-apikey github_pat_YOUR_TOKEN_HERE

Replace the default parameter by creating your own secret parameter and passing it to WithApiKey (or withApiKey):

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var apiKey = builder.AddParameter("my-gh-token", secret: true);
var chat = builder.AddGitHubModel("chat", GitHubModel.OpenAI.OpenAIGpt4oMini)
.WithApiKey(apiKey);
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(chat);
// After adding all resources, run the app...

For organization-attributed requests, pass an organization parameter:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var organization = builder.AddParameter("github-org");
var chat = builder.AddGitHubModel("chat", GitHubModel.OpenAI.OpenAIGpt4oMini, organization);
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(chat);
// After adding all resources, run the app...

When an organization is specified, the endpoint changes to https://models.github.ai/orgs/{organization}/inference and the token must be attributed to that organization in GitHub.

Add an optional health check to verify endpoint reachability and API key validity:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var chat = builder.AddGitHubModel("chat", GitHubModel.OpenAI.OpenAIGpt4oMini)
.WithHealthCheck();
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(chat);
// After adding all resources, run the app...

GitHub Models supports a broad and growing catalog of models. Use the strongly-typed constants for the most accurate list:

PublisherC# constant (examples)TypeScript enum (examples)
OpenAIGitHubModel.OpenAI.OpenAIGpt4oMiniGitHubModelName.OpenAIGpt4oMini
OpenAIGitHubModel.OpenAI.OpenAIGpt41MiniGitHubModelName.OpenAIGpt41Mini
DeepSeekGitHubModel.DeepSeek.DeepSeekV30324GitHubModelName.DeepSeekV30324
DeepSeekGitHubModel.DeepSeek.DeepSeekR1GitHubModelName.DeepSeekR1
MicrosoftGitHubModel.Microsoft.Phi4MiniInstructGitHubModelName.Phi4MiniInstruct (see note)
MetaGitHubModel.Meta.MetaLlama318BInstructGitHubModelName.MetaLlama318BInstruct

For the full catalogue, visit the GitHub Models Marketplace.

For the full reference of GitHub Models connection properties — and how consuming apps in C#, TypeScript, Python, and Go read them — see Connect to GitHub Models.