Can anyone help me spot what’s wrong with this C# code? I get the error:
Exception Caught! Message :{0} Response status code does not indicate success: 404 (Not Found). The endpoint works in Postman
public async Task<string> Send35Prompt(string strPrompt)
{
var responseBody = "";
HttpClient client = new HttpClient();
var apiKey = "MY KEY";
var endpoint = "https://api.openai.com/v1/chat/completions/";
var jsonString = strPrompt;
try
{
var content = new StringContent(strPrompt.Replace('\'', '\"'), Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);
var response = await client.PostAsync(endpoint, content);
response.EnsureSuccessStatusCode();
responseBody = await response.Content.ReadAsStringAsync();
// responseBody will contain the JSON response from the API
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
responseBody = "\nException Caught! " + "Message :{0} " + e.Message;
//Console.WriteLine("Message :{0} ", e.Message);
}
return responseBody;
}