For context, I’m using Unity C# for development. I’m facing Error 500 when creating a Run
. It works just fine on the OpenAI Playground but I’m having issues using libraries and manual implementation.
Methods I tried:
- Create Thread And Run
- Doing it separately. (i.e. Create Thread then Create Run))
Note: I have no problems on creating a Thread
and adding a Message
into it.
Libraries I tried:
- Unofficial Unity Library by RageAgainstThePixel listed in the OpenAI documentation
- Manual implementation using
UnityWebRequests
- Manual implementation using
System.Net.Http.HttpClient
- Postman tests
This is the response I get:
{ "error": { "message": "The server had an error while processing your request. Sorry about that!", "type": "server_error", "param": null, "code": null } }
Here is a minimal code for testing (manual implementation using System.Net.Http.HttpClient
Create Thread And Run):
public async Task CreateThreadAndRunAsync(string message)
{
using HttpClient client = new();
// Set headers
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {APIKey}");
client.DefaultRequestHeaders.Add("OpenAI-Organization", OrganizationID);
client.DefaultRequestHeaders.Add("OpenAI-Beta", "assistants=v1");
string postData = $@"
{{
""assistant_id"": ""{AssistantID}"",
""thread"": {{
""messages"": [
{{
""role"": ""user"",
""content"": ""{message}""
}}
]
}}
}}";
StringContent content = new(postData, Encoding.UTF8, "application/json");
try
{
HttpResponseMessage response = await client.PostAsync("https://api.openai.com/v1/threads/runs", content);
string result = await response.Content.ReadAsStringAsync();
//run = JsonConvert.DeserializeObject<Run>(result);
}
catch (Exception e)
{
Debug.LogError("Error: " + e.Message);
}
}
P.S. I can’t include links on my post.