I want to test my new assistant but I get an error when I execute the run method
the error is Bad request or error 400
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Wed, 21 Aug 2024 04:45:24 GMT
Connection: keep-alive
openai-version: 2020-10-01
openai-organization: user-b5pqqmviodjadmm0eo0v6ybh
X-Request-ID: req_bbd31e03f0fa1d6dd913888eb8bb793b
openai-processing-ms: 282
Strict-Transport-Security: max-age=15552000; includeSubDomains; preload
CF-Cache-Status: DYNAMIC
Set-Cookie: __cf_bm=MOY6INJOi3eA9FsE2uzbCSuVk1Bju0GkGpZRCnojlCc-1724215524-1.0.1.1-EWxBN4g2Yfo9kGFfwYciItdy9h3WJlaboGrGhV548uFX1ClqvSOM.anNgxEMwo6l6okYF4jpDTZfwsYDts0JM; path=/; expires=Wed, 21-Aug-24 05:15:24 GMT; domain=.api.openai.com; HttpOnly; Secure
Set-Cookie: _cfuvid=9X6w0dTVAWQJTo4DKQCk_y5dU9SOd6E.eg0TO.NHSPU-1724215524427-0.0.1.1-60480000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
X-Content-Type-Options: nosniff
Server: cloudflare
CF-RAY: 8b67f931b9a746ce-DFW
Alt-Svc: h3=":443"
Content-Type: application/json
Content-Length: 239
}}
I was thinking my old apiKey was the problem but I have created a new one and the problem continues
I have checked the url and it is correct:
URL is https://api.openai.com/v1/threads/threadId/runs
this is my code:
public async Task<string> RunAssistantAsync(string assistantId, string threadId)
{
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
_httpClient.DefaultRequestHeaders.Add("OpenAI-Beta", "assistants=v2"); // Este es el encabezado necesario para assistants
var url = $"{_apiUrl}/threads/{threadId}/runs";
var requestBody = new
{
assistant_id = assistantId
};
var jsonContent = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync(url, jsonContent);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Error al ejecutar Run: {response.StatusCode}, {response.ReasonPhrase}");
}
else
{
var responseContent = await response.Content.ReadAsStringAsync();
dynamic jsonResponse = JsonConvert.DeserializeObject(responseContent);
return jsonResponse.id;
}
}
how can solve this problem?
thanks in advance