İçeriğe geç
Docs Try Aspire
Docs Try

Get started with the Azure AI Inference integrations

Bu içerik henüz dilinizde mevcut değil.

Azure AI Inference logo 🧪 Preview

Azure AI Inference provides a unified REST API for calling AI models deployed in Azure AI Foundry and Azure AI Services. The Aspire Azure AI Inference integration lets you register an existing Azure AI Inference endpoint as a named connection in your AppHost, then inject the connection information into any consuming app — regardless of language.

Adding an Azure AI Inference connection through Aspire — rather than hard-coding endpoints and API keys in each service — gives you:

  • Centralized credential management. The API key and endpoint are stored once in the AppHost configuration and injected into each consuming app automatically.
  • Consistent connection info across languages. Once you reference the connection from a consuming app, Aspire injects the connection string as an environment variable in a predictable format that works from C#, TypeScript, Python, Go, or any other language.
  • A first-class C# client integration. C# apps can use the Aspire.Azure.AI.Inference package for dependency injection, health checks, and OpenTelemetry, all wired up from the same connection name.

Azure AI Inference doesn’t have a dedicated Aspire hosting integration. Instead, you register an existing endpoint as a named connection string in your AppHost and reference it from consuming apps.

architecture-beta

  group apphost(server)[AppHost]
  group consumer(server)[Consuming app]

  service endpoint(internet)[Azure AI Inference endpoint] in apphost

  service client(iconoir:server-connection)[Client integration] in consumer
  service app(server)[App] in consumer

  endpoint:R --> L:client
  client:R --> L:app

Getting there is a two-step process: register the connection string in your AppHost, then connect to the endpoint from each app that needs it.

  1. Register the Azure AI Inference connection in your AppHost

    Section titled “Register the Azure AI Inference connection in your AppHost”

    Add a named connection string to your AppHost that points to your existing Azure AI Inference endpoint. Aspire injects the connection information into each consuming app that references it.

    C# — 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 connection string in your AppHost’s configuration — typically in User Secrets during local development — under the ConnectionStrings key:

    JSON — User Secrets
    {
    "ConnectionStrings": {
    "ai-foundry": "Endpoint=https://{endpoint}/;Key={apikey};DeploymentId={deploymentName}"
    }
    }
  2. When you reference the connection from a consuming app, Aspire injects the connection string as an environment variable. See Connect to Azure AI Inference for the connection string format, per-language examples for C#, Go, Python, and TypeScript, and the full C# client integration reference.

    Connect to Azure AI Inference