Hi, I am getting 401 missing bearer or basic authentication in header when calling the Create message API even though the bearer is indeed attached to the header, what happens? it works perfectly fine with postman
Endpoint is also correct, here is the code snippet.
public async Task<OpenAiMessage?> CreateMessage(string threadId, CreateMessageRequest request)
{
var requestUri = $"{Endpoints.Threads}/{threadId}/messages/";
var requestBody = JsonConvert.SerializeObject(request);
using (var httpContent = new StringContent(requestBody, Encoding.UTF8, "application/json"))
{
try
{
Console.WriteLine($"Headers: {JsonConvert.SerializeObject(_httpClient.DefaultRequestHeaders)}");
Console.WriteLine($"Request Body: {requestBody}");
using (var response = await _httpClient.PostAsync(requestUri, httpContent))
{
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<OpenAiMessage>(responseBody);
}
}
catch (HttpRequestException ex)
{
// Log the exception, handle it, or rethrow with additional context
Console.WriteLine($"Failed to send message: {ex.Message}");
return null;
}
}
}