Here is the code that I have in C#. It worked perfectly before. I use gpt-3.5-turbo model.
Now it returns BadRequest (400).
I verified that ApiKey is correct.
The URL is: https://api.openai.com/v1/chat/completions
So what do I do wrong?
HttpClient client = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
string jsonContent = JsonConvert.SerializeObject(request, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
var stringContent = new StringContent(jsonContent, UnicodeEncoding.UTF8, "application/json");
string url = String.Format("{0}/chat/completions", Api.BaseUrl);
Log.VerboseFormat("Calling SendAsync with URL: {0}, and Engine: {1}", url, request.Model);
using (HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, url))
{
string apiKey = Api.mConfig.SafeStorage.DecryptString(Api.mConfig.ApiKey);
req.Content = stringContent;
req.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);
req.Headers.Add("Accept", "application/json");
req.Headers.Add("User-Agent", "GSS/OpenAI_GPT3");
var response = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
// API failed with BadRequest (400)
}
The json string input: