I am trying to get started using the Azure OpenAI tools to integrate OpenAI functionality into an application. But I have stranded at the first hurdle. Initializing the OpenAIClient object requires two parameters, endpoint url and key for my Azure AI subscription.
using Azure;
using Azure.AI.OpenAI;
using OpenAI;
using OpenAI.Chat;
string endpoint = "/";
string key = "MYKEYVALUES";
OpenAIClient azureClient = new(
new Uri(endpoint),
new AzureKeyCredential(key));
However, I get an error for each of the two variables in the constructor:
- new Uri(endpoint): Cannot convert from 'System.Uri' to 'System.ClientModel.ApiKeyCredential'
- new AzureKeyCredential(key): Cannot convert from Azure.AzureKeyCredential to OpenAi.OpenAIClientOptions
These are basic setup steps included in several introductory tutorials/quickstarts on this, so most likely a super-basic issue. But would very much appreciate help to understand and fix this.
I am trying to get started using the Azure OpenAI tools to integrate OpenAI functionality into an application. But I have stranded at the first hurdle. Initializing the OpenAIClient object requires two parameters, endpoint url and key for my Azure AI subscription.
using Azure;
using Azure.AI.OpenAI;
using OpenAI;
using OpenAI.Chat;
string endpoint = "https://MYURL.openai.azure/";
string key = "MYKEYVALUES";
OpenAIClient azureClient = new(
new Uri(endpoint),
new AzureKeyCredential(key));
However, I get an error for each of the two variables in the constructor:
- new Uri(endpoint): Cannot convert from 'System.Uri' to 'System.ClientModel.ApiKeyCredential'
- new AzureKeyCredential(key): Cannot convert from Azure.AzureKeyCredential to OpenAi.OpenAIClientOptions
These are basic setup steps included in several introductory tutorials/quickstarts on this, so most likely a super-basic issue. But would very much appreciate help to understand and fix this.
Share Improve this question asked Nov 18, 2024 at 19:13 Proposition JoeProposition Joe 4814 gold badges10 silver badges25 bronze badges 01 Answer
Reset to default 0The reason you are getting this error is because the constructor you are using is for AzureOpenAIClient
and not OpenAIClient
.
Please change your code to
AzureOpenAIClient azureClient = new(
new Uri(endpoint),
new AzureKeyCredential(key));