async Task testexample()
{
var client = new RestSharp.RestClient("https://api.openai.com/v1/");
var request = new RestSharp.RestRequest($"threads/thread_L8******************JJ/messages/", RestSharp.Method.Post);
request.AddHeader("Authorization", "Bearer ************");
request.AddHeader("OpenAI-Beta", "assistants=v2");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\"role\":\"user\",\"content\":\"Hello, this is a test message.\"}", RestSharp.ParameterType.RequestBody);
RestSharp.RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine("Response Status: " + response.StatusCode);
Console.WriteLine("Response Body: " + response.Content);
}
API key is hard-coded but i still get unauthorized, Missing bearer or basic authentication in header.
is this an openapi bug?, postman works great meaning my apikey allowed to call the api.
Please help.
Assuming your API key is correct, maybe try adding your API key to the client rather than the request using the JWT authenticator instead?
var options = new RestClientOptions("https://api.openai.com/v1/") {
Authenticator = new JwtAuthenticator(sk**********);
};
var client = new RestClient(options);
[image]
var request = new RestSharp.RestRequest($"threads/thread_L8******************JJ/messages/", RestSharp.Method.Post);
↓
var request = new RestSharp.RestRequest($"threads/thread_L8******************JJ/messages", RestSharp.Method.Post);