Set up GitHub Models in the AppHost
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.
Installation
Section titled “Installation”To start building an Aspire app that uses GitHub Models, install the 📦 Aspire.Hosting.GitHub.Models NuGet package:
aspire add github-modelsLearn more about aspire add in the command reference.
Or, choose a manual installation approach:
#:package Aspire.Hosting.GitHub.Models@*<PackageReference Include="Aspire.Hosting.GitHub.Models" Version="*" />aspire add github-modelsLearn more about aspire add in the command reference.
This updates your aspire.config.json with the GitHub Models hosting integration package:
{ "packages": { "Aspire.Hosting.GitHub.Models": "13.3.0" }}Add a GitHub Model resource
Section titled “Add a GitHub Model resource”Once you’ve installed the hosting integration in your AppHost project, you can add a GitHub Model resource:
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...import { createBuilder, GitHubModelName } from './.modules/aspire.js';
const builder = await createBuilder();
const chat = await builder.addGitHubModel("chat", GitHubModelName.OpenAIGpt4oMini);
await builder.addNodeApp("api", "./api", "index.js") .withReference(chat);
// After adding all resources, run the app...-
Calling
AddGitHubModel(oraddGitHubModel) creates aGitHubModelResource. It registers a secret parameter for the API key that defaults to theGITHUB_TOKENenvironment variable. -
The model identifier selects which GitHub-hosted model to target. In C#, use the strongly-typed
GitHubModelconstants grouped by publisher; in TypeScript, use theGitHubModelNameenum. -
The AppHost reference call configures a connection in the consuming project named after the resource (for example,
chatin the preceding example).
Use a model identifier string
Section titled “Use a model identifier string”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):
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...import { createBuilder } from './.modules/aspire.js';
const builder = await createBuilder();
const chat = await builder.addGitHubModelById("chat", "openai/gpt-4o-mini");
await builder.addNodeApp("api", "./api", "index.js") .withReference(chat);
// After adding all resources, run the app...Use default API key parameter
Section titled “Use default API key parameter”Calling AddGitHubModel("chat", ...) (or addGitHubModel("chat", ...)) automatically creates a secret parameter named chat-gh-apikey. Aspire resolves its value in this order:
- The
Parameters:chat-gh-apikeyconfiguration key (user secrets,appsettings.*, or environment variables). - The
GITHUB_TOKENenvironment 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:
aspire secret set Parameters:chat-gh-apikey github_pat_YOUR_TOKEN_HEREUse a custom API key parameter
Section titled “Use a custom API key parameter”Replace the default parameter by creating your own secret parameter and passing it to WithApiKey (or withApiKey):
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...import { createBuilder, GitHubModelName } from './.modules/aspire.js';
const builder = await createBuilder();
const apiKey = await builder.addParameter("my-gh-token", { secret: true });
const chat = await builder.addGitHubModel("chat", GitHubModelName.OpenAIGpt4oMini);await chat.withApiKey(apiKey);
await builder.addNodeApp("api", "./api", "index.js") .withReference(chat);
// After adding all resources, run the app...Specify an organization
Section titled “Specify an organization”For organization-attributed requests, pass an organization parameter:
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...import { createBuilder, GitHubModelName } from './.modules/aspire.js';
const builder = await createBuilder();
const organization = await builder.addParameter("github-org");
const chat = await builder.addGitHubModel("chat", GitHubModelName.OpenAIGpt4oMini, { organization,});
await builder.addNodeApp("api", "./api", "index.js") .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 a health check
Section titled “Add a health check”Add an optional health check to verify endpoint reachability and API key validity:
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...import { createBuilder, GitHubModelName } from './.modules/aspire.js';
const builder = await createBuilder();
const chat = await builder.addGitHubModel("chat", GitHubModelName.OpenAIGpt4oMini);await chat.withHealthCheck();
await builder.addNodeApp("api", "./api", "index.js") .withReference(chat);
// After adding all resources, run the app...Available models
Section titled “Available models”GitHub Models supports a broad and growing catalog of models. Use the strongly-typed constants for the most accurate list:
| Publisher | C# constant (examples) | TypeScript enum (examples) |
|---|---|---|
| OpenAI | GitHubModel.OpenAI.OpenAIGpt4oMini | GitHubModelName.OpenAIGpt4oMini |
| OpenAI | GitHubModel.OpenAI.OpenAIGpt41Mini | GitHubModelName.OpenAIGpt41Mini |
| DeepSeek | GitHubModel.DeepSeek.DeepSeekV30324 | GitHubModelName.DeepSeekV30324 |
| DeepSeek | GitHubModel.DeepSeek.DeepSeekR1 | GitHubModelName.DeepSeekR1 |
| Microsoft | GitHubModel.Microsoft.Phi4MiniInstruct | GitHubModelName.Phi4MiniInstruct (see note) |
| Meta | GitHubModel.Meta.MetaLlama318BInstruct | GitHubModelName.MetaLlama318BInstruct |
For the full catalogue, visit the GitHub Models Marketplace.
Connection properties
Section titled “Connection properties”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.