I am getting error as below while creating a message using assistant api as follows, using dotnet c#
My code is as below:
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add(“Authorization”, $“Bearer {apiKey}”);
httpClient.DefaultRequestHeaders.Add(“OpenAI-Beta”, “assistants=v1”);
var requestBody = $@"{{""messages"": [{{ ""role"": ""user"",""content"": ""Can you brief about NewYork City?""}}]}}";
HttpContent content = new StringContent(requestBody, Encoding.UTF8, "application/json");
string url = $"https://api.openai.com/v1/threads/{threadId}/messages";
var response = await httpClient.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
}
else
{
var result = await response.Content.ReadAsStringAsync();
return null;
}
}
When Executing this, i am getting below error as reponse :
“{\n "error": {\n "message": "3 validation errors for Request\nbody → role\n field required (type=value_error.missing)\nbody → content\n field required (type=value_error.missing)\nbody → messages\n extra fields not permitted (type=value_error.extra)",\n "type": "invalid_request_error",\n "param": null,\n "code": null\n }\n}”
Can anybody tell a solution ? or Am I doing something wrong in my coding?