[Bug]: PHP Fatal error: Uncaught TypeError
Description
PHP Fatal error: Uncaught TypeError: OpenAI\Responses\Threads\Messages\ThreadMessageResponse::from(): Argument #1 ($attributes) must be of type array, string given, called in .../vendor/openai-php/client/src/Resources/ThreadsMessages.php on line 32
Steps To Reproduce
This error happens irregularly during following call chain:
$client->threads()->messages()->create( $thread_id, $message );
OpenAI PHP Client Version
v0.10.3
PHP Version
8.2.16
Notes
After error_log debugging I found that API replied with 'Bad Gateway' response and 'Content-Type: text/plain`.
Yeah generally at the moment if the response isn't JSON - the handling isn't the best. This has manifested differently depending on the call. Some others related:
- https://github.com/openai-php/client/issues/341
- https://github.com/openai-php/client/issues/339
Also https://github.com/openai-php/client/issues/478
In my case this exact issue occurs when VectorStoresFiles::create() is returning "error code: 502" which is then passed as the argument to VectorStoreFileResponse::from(). I'm trying to try/catch these errors by hacking these methods, but it's not quite working yet, and thus breaking processing.
We have a fix in progress to rework a bit of the exception handling for that use-case. Trying to gather more samples in the field of the odd OpenAI issues to confirm: https://github.com/openai-php/client/pull/553
Thanks! This has been bugging us for a few months, and even more in recent weeks