Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,896 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Here is my c# code(.net 8.0)
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
string openAiApiKey= "xxxxxxxxxxxxxxx";
Kernel kernel=Kernel.CreateBuilder().AddOpenAIChatCompletion("gpt-3.5-turbo", "https://xxxxxx.openai.azure.com/", openAiApiKey).Build();
Console.WriteLine("Build successfully");
while (true)
{
Console.WriteLine("Q:");
Console.WriteLine(await kernel.InvokePromptAsync(Console.ReadLine()));
}
It fails with below error
Build successfully
Q:
Hello
Unhandled exception. Microsoft.SemanticKernel.HttpOperationException: Incorrect API key provided: https://************************com/. You can find your API key at https://platform.openai.com/account/api-keys.
Status: 401 (Unauthorized)
ErrorCode: invalid_api_key
Content:
{
"error": {
"message": "Incorrect API key provided: https://************************com/. You can find your API key at https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}
Headers:
Date: Fri, 28 Jun 2024 23:36:53 GMT
Connection: keep-alive
Vary: REDACTED
X-Request-ID: REDACTED
Strict-Transport-Security: REDACTED
CF-Cache-Status: REDACTED
Set-Cookie: REDACTED
Server: cloudflare
CF-RAY: REDACTED
Alt-Svc: REDACTED
Content-Type: application/json; charset=utf-8
Content-Length: 286
I got the key and endpoint from 'Keys and Endpoint'
Resolved by replacing it with AddAzureOpenAIChatCompletion