# Set up Azure AI Inference in the AppHost

<Image
  src={aiFoundryIcon}
  alt="Azure AI Inference logo"
  width={100}
  height={100}
  class:list={'float-inline-left icon'}
  data-zoom-off
/>

<Badge text="🧪 Preview" variant="note" size="large" />

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](/integrations/cloud/azure/azure-ai-inference/azure-ai-inference-get-started/). For how consuming apps read the connection information this page exposes, see [Connect to Azure AI Inference](/integrations/cloud/azure/azure-ai-inference/azure-ai-inference-connect/).

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

```csharp title="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();
```

```typescript title="apphost.mts"
import { createBuilder } from "./.aspire/modules/aspire.mjs";

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

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 title="JSON — User Secrets"
{
  "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`). |
**Note:** Connection strings represent any connection information — database connections, message brokers, endpoint URIs, and other services. For more information, see [Add existing Azure resources with connection strings](/integrations/cloud/azure/overview/#add-existing-azure-resources-with-connection-strings).

## 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](/integrations/cloud/azure/azure-ai-inference/azure-ai-inference-connect/).