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 { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder, type GitHubModelName = "AI21Jamba15Large" | "CohereCommandA" | "CohereCommandR082024" | "CohereCommandRPlus082024" | "DeepSeekR1" | "DeepSeekR10528" | "DeepSeekV30324" | "Llama4Maverick17B128EInstructFP8" | "Llama4Scout17B16EInstruct" | "Llama3211BVisionInstruct" | "Llama3290BVisionInstruct" | "Llama3370BInstruct" | "MetaLlama31405BInstruct" | "MetaLlama318BInstruct" | "MaiDSR1" | "Phi4" | "Phi4MiniInstruct" | "Phi4MiniReasoning" | "Phi4MultimodalInstruct" | "Phi4Reasoning" | "Codestral2501" | "Ministral3B" | "MistralMedium32505" | "MistralSmall31" | ... 18 more ... | "Grok3Mini"const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const chat: GitHubModelResource
chat = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addGitHubModel(name: string, model: GitHubModelName, options?: { organization?: string | ParameterResource;}): GitHubModelResource (+1 overload)
Adds a GitHub Model resource to the distributed application model.
addGitHubModel("chat", const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName.type OpenAIGpt4oMini: "OpenAIGpt4oMini"
OpenAIGpt4oMini);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const chat: GitHubModelResource
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 { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const chat: GitHubModelResource
chat = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addGitHubModelById(name: string, modelId: string, options?: { organization?: string | ParameterResource;}): GitHubModelResource (+1 overload)
Adds a GitHub Model resource using a model identifier string.
addGitHubModelById("chat", "openai/gpt-4o-mini");
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const chat: GitHubModelResource
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 { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder, type GitHubModelName = "AI21Jamba15Large" | "CohereCommandA" | "CohereCommandR082024" | "CohereCommandRPlus082024" | "DeepSeekR1" | "DeepSeekR10528" | "DeepSeekV30324" | "Llama4Maverick17B128EInstructFP8" | "Llama4Scout17B16EInstruct" | "Llama3211BVisionInstruct" | "Llama3290BVisionInstruct" | "Llama3370BInstruct" | "MetaLlama31405BInstruct" | "MetaLlama318BInstruct" | "MaiDSR1" | "Phi4" | "Phi4MiniInstruct" | "Phi4MiniReasoning" | "Phi4MultimodalInstruct" | "Phi4Reasoning" | "Codestral2501" | "Ministral3B" | "MistralMedium32505" | "MistralSmall31" | ... 18 more ... | "Grok3Mini"const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const apiKey: ParameterResource
apiKey = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addParameter(name: string, options?: { value?: string; publishValueAsDefault?: boolean; secret?: boolean;}): ParameterResource (+1 overload)
Adds a parameter resource
addParameter("my-gh-token", { secret?: boolean | undefined
secret: true });
const const chat: GitHubModelResource
chat = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addGitHubModel(name: string, model: GitHubModelName, options?: { organization?: string | ParameterResource;}): GitHubModelResource (+1 overload)
Adds a GitHub Model resource to the distributed application model.
addGitHubModel("chat", const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName.type OpenAIGpt4oMini: "OpenAIGpt4oMini"
OpenAIGpt4oMini);await const chat: GitHubModelResource
chat.GitHubModelResource.withApiKey(apiKey: string | ParameterResource): GitHubModelResource
Configures the API key for the GitHub Model resource.
withApiKey(const apiKey: ParameterResource
apiKey);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const chat: GitHubModelResource
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 { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder, type GitHubModelName = "AI21Jamba15Large" | "CohereCommandA" | "CohereCommandR082024" | "CohereCommandRPlus082024" | "DeepSeekR1" | "DeepSeekR10528" | "DeepSeekV30324" | "Llama4Maverick17B128EInstructFP8" | "Llama4Scout17B16EInstruct" | "Llama3211BVisionInstruct" | "Llama3290BVisionInstruct" | "Llama3370BInstruct" | "MetaLlama31405BInstruct" | "MetaLlama318BInstruct" | "MaiDSR1" | "Phi4" | "Phi4MiniInstruct" | "Phi4MiniReasoning" | "Phi4MultimodalInstruct" | "Phi4Reasoning" | "Codestral2501" | "Ministral3B" | "MistralMedium32505" | "MistralSmall31" | ... 18 more ... | "Grok3Mini"const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const organization: ParameterResource
organization = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addParameter(name: string, options?: { value?: string; publishValueAsDefault?: boolean; secret?: boolean;}): ParameterResource (+1 overload)
Adds a parameter resource
addParameter("github-org");
const const chat: GitHubModelResource
chat = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addGitHubModel(name: string, model: GitHubModelName, options?: { organization?: string | ParameterResource;}): GitHubModelResource (+1 overload)
Adds a GitHub Model resource to the distributed application model.
addGitHubModel("chat", const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName.type OpenAIGpt4oMini: "OpenAIGpt4oMini"
OpenAIGpt4oMini, { organization?: string | ParameterResource | undefined
organization,});
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const chat: GitHubModelResource
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 { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder, type GitHubModelName = "AI21Jamba15Large" | "CohereCommandA" | "CohereCommandR082024" | "CohereCommandRPlus082024" | "DeepSeekR1" | "DeepSeekR10528" | "DeepSeekV30324" | "Llama4Maverick17B128EInstructFP8" | "Llama4Scout17B16EInstruct" | "Llama3211BVisionInstruct" | "Llama3290BVisionInstruct" | "Llama3370BInstruct" | "MetaLlama31405BInstruct" | "MetaLlama318BInstruct" | "MaiDSR1" | "Phi4" | "Phi4MiniInstruct" | "Phi4MiniReasoning" | "Phi4MultimodalInstruct" | "Phi4Reasoning" | "Codestral2501" | "Ministral3B" | "MistralMedium32505" | "MistralSmall31" | ... 18 more ... | "Grok3Mini"const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName } from './.modules/aspire.js';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const chat: GitHubModelResource
chat = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addGitHubModel(name: string, model: GitHubModelName, options?: { organization?: string | ParameterResource;}): GitHubModelResource (+1 overload)
Adds a GitHub Model resource to the distributed application model.
addGitHubModel("chat", const GitHubModelName: { readonly AI21Jamba15Large: "AI21Jamba15Large"; readonly CohereCommandA: "CohereCommandA"; readonly CohereCommandR082024: "CohereCommandR082024"; readonly CohereCommandRPlus082024: "CohereCommandRPlus082024"; readonly DeepSeekR1: "DeepSeekR1"; readonly DeepSeekR10528: "DeepSeekR10528"; readonly DeepSeekV30324: "DeepSeekV30324"; readonly Llama4Maverick17B128EInstructFP8: "Llama4Maverick17B128EInstructFP8"; readonly Llama4Scout17B16EInstruct: "Llama4Scout17B16EInstruct"; readonly Llama3211BVisionInstruct: "Llama3211BVisionInstruct"; ... 32 more ...; readonly Grok3Mini: "Grok3Mini";}
Enum Aspire.Hosting.GitHub.GitHubModelName
GitHubModelName.type OpenAIGpt4oMini: "OpenAIGpt4oMini"
OpenAIGpt4oMini);await const chat: GitHubModelResource
chat.GitHubModelResource.withHealthCheck(): GitHubModelResource
Adds a health check for the GitHub Model resource.
withHealthCheck();
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource
Adds a Node.js application resource
addNodeApp("api", "./api", "index.js") .ExecutableResource.withReference(source: EndpointReference | string | uri, options?: { connectionName?: string; optional?: boolean; name?: string;} | undefined): NodeAppResource (+2 overloads)
Adds a reference to another resource
withReference(const chat: GitHubModelResource
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.