Aspire.Hosting.OpenAI
13.5.3
Prefix Reserved
dotnet add package Aspire.Hosting.OpenAI --version 13.5.3
NuGet\Install-Package Aspire.Hosting.OpenAI -Version 13.5.3
<PackageReference Include="Aspire.Hosting.OpenAI" Version="13.5.3" />
<PackageVersion Include="Aspire.Hosting.OpenAI" Version="13.5.3" />
<PackageReference Include="Aspire.Hosting.OpenAI" />
paket add Aspire.Hosting.OpenAI --version 13.5.3
#r "nuget: Aspire.Hosting.OpenAI, 13.5.3"
#:package Aspire.Hosting.OpenAI@13.5.3
#addin nuget:?package=Aspire.Hosting.OpenAI&version=13.5.3
#tool nuget:?package=Aspire.Hosting.OpenAI&version=13.5.3
OpenAI hosting integration
Use this integration to model, configure, and orchestrate OpenAI resources and models in an Aspire solution.
Getting started
Prerequisites
- An OpenAI account with access to the OpenAI API
- OpenAI API key
Add the integration
From your AppHost directory, add the Aspire.Hosting.OpenAI integration with the Aspire CLI:
aspire add Aspire.Hosting.OpenAI
Usage example
In the AppHost, add an OpenAI resource and one or more model resources, then reference them from other resources as needed:
C#
var builder = DistributedApplication.CreateBuilder(args);
var openai = builder.AddOpenAI("openai");
var chat = openai.AddModel("chat", "gpt-4o-mini");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(chat);
TypeScript
import { createBuilder } from "./.aspire/modules/aspire.mjs";
const builder = await createBuilder();
const openai = await builder.addOpenAI("openai");
const chat = await openai.addModel("chat", "gpt-4o-mini");
const myService = await builder.addNodeApp("myService", "../my-service", "server.js")
.withReference(chat);
Configuration
The OpenAI resources can be configured with the following options:
API Key
The API key is configured on the parent OpenAI resource via a parameter named {resource_name}-openai-apikey or the OPENAI_API_KEY environment variable.
From your AppHost directory, set the parameter value with aspire secret set:
aspire secret set Parameters:openai-openai-apikey "YOUR_OPENAI_API_KEY_HERE"
You can replace the parent API key with a custom parameter on the parent resource:
var apiKey = builder.AddParameter("my-api-key", secret: true);
var openai = builder.AddOpenAI("openai").WithApiKey(apiKey);
// share a single key across multiple models
var chat = openai.AddModel("chat", "gpt-4o-mini");
var embeddings = openai.AddModel("embeddings", "text-embedding-3-small");
From your AppHost directory, set the custom parameter values with aspire secret set:
aspire secret set Parameters:my-api-key "YOUR_OPENAI_API_KEY_HERE"
aspire secret set Parameters:alt-key "ANOTHER_OPENAI_API_KEY"
Available Models
OpenAI supports various AI models. Some popular options include:
gpt-4o-minigpt-4ogpt-4-turbogpt-3.5-turbotext-embedding-3-smalltext-embedding-3-largedall-e-3whisper-1
Check the OpenAI Models documentation for the most up-to-date list of available models.
Custom endpoint
By default, the OpenAI service endpoint is https://api.openai.com/v1. To use an OpenAI-compatible gateway or self-hosted endpoint, set a custom endpoint on the parent resource:
var openai = builder.AddOpenAI("openai")
.WithEndpoint("https://my-gateway.example.com/v1");
var chat = openai.AddModel("chat", "gpt-4o-mini");
Both the parent and model connection strings will include the custom endpoint.
Connection Properties
When you reference an OpenAI resource using WithReference, the following connection properties are made available to the consuming project:
OpenAIResource
The OpenAI resource exposes the following connection properties:
| Property Name | Description |
|---|---|
Endpoint |
The base endpoint URI for the OpenAI API, with the format https://api.openai.com/v1 |
Uri |
The endpoint URI (same as Endpoint), with the format https://api.openai.com/v1 |
Key |
The API key for authentication |
OpenAI model
The OpenAI model resource combines the parent properties above and adds the following connection property:
| Property Name | Description |
|---|---|
ModelName |
The model identifier for inference requests, for instance gpt-4o-mini |
Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called chat becomes CHAT_URI.
Additional documentation
- https://aspire.dev/integrations/gallery/
- https://aspire.dev/integrations/ai/openai/openai-host/
- https://platform.openai.com/docs/models
Feedback & contributing
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Aspire.Hosting (>= 13.5.3)
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Google.Protobuf (>= 3.34.1)
- Grpc.AspNetCore (>= 2.80.0)
- Grpc.Net.ClientFactory (>= 2.80.0)
- Grpc.Tools (>= 2.80.0)
- Humanizer.Core (>= 3.0.10)
- JsonPatch.Net (>= 5.0.2)
- KubernetesClient (>= 19.0.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.11)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.30)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.11)
- Microsoft.Extensions.Hosting (>= 10.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Http (>= 10.0.11)
- Microsoft.Extensions.Logging (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Options (>= 10.0.11)
- Microsoft.Extensions.Primitives (>= 10.0.11)
- ModelContextProtocol (>= 1.3.0)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.15.3)
- OpenTelemetry.Extensions.Hosting (>= 1.15.3)
- Polly.Core (>= 8.6.6)
- Semver (>= 3.0.0)
- StreamJsonRpc (>= 2.25.29)
- System.IO.Hashing (>= 10.0.8)
- System.Text.Json (>= 10.0.11)
- YamlDotNet (>= 16.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Aspire.Hosting.OpenAI:
| Package | Downloads |
|---|---|
|
Nabs.Launchpad.Core.Aspire.Hosting
Package Description |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on Aspire.Hosting.OpenAI:
| Repository | Stars |
|---|---|
|
foxminchan/BookWorm
The practical implementation of Aspire using Microservices, AI-Agents
|
|
|
davidfowl/aspire-ai-chat-demo
Aspire AI Chat is a full-stack chat sample that combines modern technologies to deliver a ChatGPT-like experience.
|
|
|
Azure-Samples/interview-coach-agent-framework
Interview coach application using Microsoft Agent Framework | https://aka.ms/agentframework/interviewcoach
|
| Version | Downloads | Last Updated |
|---|---|---|
| 13.5.3 | 421 | 8/25/2026 |
| 13.5.2 | 2,774 | 8/21/2026 |
| 13.5.1 | 158 | 8/20/2026 |
| 13.5.0 | 443 | 8/18/2026 |
| 13.4.6 | 3,816 | 6/19/2026 |
| 13.4.5 | 532 | 6/17/2026 |
| 13.4.4 | 320 | 6/15/2026 |
| 13.4.3 | 972 | 6/8/2026 |
| 13.4.2 | 1,168 | 6/3/2026 |
| 13.4.1 | 162 | 6/3/2026 |
| 13.4.0 | 1,583 | 6/1/2026 |
| 13.3.5 | 1,344 | 5/21/2026 |
| 13.3.4 | 217 | 5/19/2026 |
| 13.3.3 | 1,032 | 5/15/2026 |
| 13.3.2 | 376 | 5/14/2026 |
| 13.3.1 | 477 | 5/12/2026 |
| 13.3.0 | 978 | 5/7/2026 |
| 13.2.4 | 1,172 | 4/24/2026 |
| 13.2.3 | 533 | 4/21/2026 |
| 13.2.2 | 1,548 | 4/8/2026 |