Lewati ke konten
Docs Try Aspire
Docs Try

Set up Azure AI Inference in the AppHost

Konten ini belum tersedia dalam bahasa Anda.

Azure AI Inference logo 🧪 Preview

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.

Use AddConnectionString to register an existing Azure AI Inference endpoint with your AppHost, then reference it from any consuming app:

AppHost.cs
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();

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):

JSON — User Secrets
{
"ConnectionStrings": {
"ai-foundry": "Endpoint=https://{endpoint}/;Key={apikey};DeploymentId={deploymentName}"
}
}

The connection string supports the following segments:

SegmentDescription
EndpointThe Azure AI Inference endpoint URL — for example, https://{your-foundry-resource}.services.ai.azure.com/models.
KeyThe API key for the Azure AI Inference endpoint. Omit when the consuming app authenticates with DefaultAzureCredential.
DeploymentIdThe name of the deployed model (for example, gpt-4o).

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.