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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aspire.Hosting.OpenAI" Version="13.5.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aspire.Hosting.OpenAI" Version="13.5.3" />
                    
Directory.Packages.props
<PackageReference Include="Aspire.Hosting.OpenAI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aspire.Hosting.OpenAI --version 13.5.3
                    
#r "nuget: Aspire.Hosting.OpenAI, 13.5.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aspire.Hosting.OpenAI@13.5.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aspire.Hosting.OpenAI&version=13.5.3
                    
Install as a Cake Addin
#tool nuget:?package=Aspire.Hosting.OpenAI&version=13.5.3
                    
Install as a Cake Tool

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-mini
  • gpt-4o
  • gpt-4-turbo
  • gpt-3.5-turbo
  • text-embedding-3-small
  • text-embedding-3-large
  • dall-e-3
  • whisper-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

Feedback & contributing

https://github.com/microsoft/aspire

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed