client icon indicating copy to clipboard operation
client copied to clipboard

[Bug]: PHP Fatal error: Uncaught TypeError

Open smazur opened this issue 10 months ago • 5 comments

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`.

smazur avatar Apr 08 '25 06:04 smazur

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

iBotPeaches avatar Apr 08 '25 14:04 iBotPeaches

Also https://github.com/openai-php/client/issues/478

bytestream avatar Apr 09 '25 09:04 bytestream

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.

datawench avatar Apr 23 '25 12:04 datawench

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

iBotPeaches avatar Apr 23 '25 12:04 iBotPeaches

Thanks! This has been bugging us for a few months, and even more in recent weeks

yhael-aloware avatar Apr 24 '25 03:04 yhael-aloware