Skip to content

Commit 96a9bdf

Browse files
author
Maryanne Gichohi
committed
Update doc on using API Key to connect to an Azure OpenAI resource
1 parent f5a7074 commit 96a9bdf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

articles/azure-app-configuration/quickstart-chat-completion-dotnet.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,36 @@ In this quickstart you will create a .NET console app with dynamic configuration
117117
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(modelEndpoint), credential);
118118
```
119119

120+
1. Alternatively, you can authenticate to your Azure OpenAI resource using an API key stored as a Key Vault reference in App Configuration with the key name "ChatLLM:ApiKey". Ensure to [grant your app access to Key Vault](./use-key-vault-references-dotnet-core.md#grant-your-app-access-to-key-vault). To read the Key Vault reference, update your configuration builder code in _Program.cs_ as follows:
121+
122+
```csharp
123+
IConfiguration configuration = new ConfigurationBuilder()
124+
.AddAzureAppConfiguration(options =>
125+
{
126+
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
127+
128+
options.Connect(new Uri(endpoint), credential)
129+
.Select("ChatLLM*")
130+
.ConfigureKeyVault(keyVaultOptions =>
131+
{
132+
keyVaultOptions.SetCredential(credential);
133+
})
134+
.ConfigureRefresh(refresh =>
135+
{
136+
refresh.RegisterAll()
137+
.SetRefreshInterval(TimeSpan.FromSeconds(10));
138+
});
139+
140+
_refresher = options.GetRefresher();
141+
}).Build();
142+
143+
string apiKey = configuration["ChatLLM:ApiKey"];
144+
145+
// Initialize the AzureOpenAIClient with API key
146+
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(modelEndpoint), new AzureKeyCredential(apiKey));
147+
148+
```
149+
120150
1. Next, update the existing code in _Program.cs_ file to configure the chat completion options:
121151

122152
```csharp

0 commit comments

Comments
 (0)