Set up Azure AI Inference in the AppHost
Dette indhold er ikke tilgængeligt i dit sprog endnu.
This article is the reference for using Azure AI Inference in your AppHost. Aspire doesn’t ship a dedicated Azure AI Inference hosting package — instead, you register an existing Azure AI Inference endpoint as a named connection string that consuming apps can reference.
If you’re new to Azure AI Inference, start with Get started with the Azure AI Inference integrations. For how consuming apps read the connection information this page exposes, see Connect to Azure AI Inference.
Add an Azure AI Inference connection
Section titled “Add an Azure AI Inference connection”Use AddConnectionString to register an existing Azure AI Inference endpoint with your AppHost, then reference it from any consuming app:
var builder = DistributedApplication.CreateBuilder(args);
var aiInference = builder.AddConnectionString("ai-foundry");
builder.AddProject<Projects.ExampleProject>("myapp") .WithReference(aiInference);
// After adding all resources, run the app...builder.Build().Run();import { createBuilder } from "./.modules/aspire.js";
const builder = await createBuilder();
const aiInference = await builder.addConnectionString("ai-foundry");
const myapp = await builder.addProject("myapp", "../ExampleProject/ExampleProject.csproj");await myapp.withReference(aiInference);
await builder.build().run();Configure the connection string
Section titled “Configure the connection string”Store the Azure AI Inference connection string in your AppHost’s configuration. During local development, use User Secrets to keep credentials out of source control. The key must match the resource name you passed to AddConnectionString (“ai-foundry” in the example above):
{ "ConnectionStrings": { "ai-foundry": "Endpoint=https://{endpoint}/;Key={apikey};DeploymentId={deploymentName}" }}The connection string supports the following segments:
| Segment | Description |
|---|---|
Endpoint | The Azure AI Inference endpoint URL — for example, https://{your-foundry-resource}.services.ai.azure.com/models. |
Key | The API key for the Azure AI Inference endpoint. Omit when the consuming app authenticates with DefaultAzureCredential. |
DeploymentId | The name of the deployed model (for example, gpt-4o). |
Connection properties
Section titled “Connection properties”For the consumer-side view of how this connection is exposed as environment variables — and for per-language client examples — see Connect to Azure AI Inference.