openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.57k stars 466 forks source link

Threads (beta) list endpoint needs to be POST request not GET, also does not return expected $attributes #268

Closed vesper8 closed 7 months ago

vesper8 commented 7 months ago

In your beta's current implementation it uses Payload::list which uses a GET method which results in this error:

Your request to GET /v1/threads must be made with a session key (that is, it can only be made from the browser). You made it with the following key type: secret.

After a little digging on this error, turns out the request must be a POST request. I tested this and it does indeed work if using a POST request.

Then it runs into another error in ThreadListResponse because the expected $attributes does not contain the expected keys. I dd($attributes) and it includes

array:4 [
  "id" => "thread_xxx"
  "object" => "thread"
  "created_at" => 1700489465
  "metadata" => []
]

So it's missing pretty much all the attributes expected here https://github.com/openai-php/client/blob/a910d16f3b26e52c368f33773132c45fc2014085/src/Responses/Threads/ThreadListResponse.php#L45

gehrisandro commented 7 months ago

Hi @vesper8

Looks like the implementation of this endpoint has changed, as it has worked last week properly.

But this endpoint was never documented and therefore it may was never intended to be used via the API. I will check the behaviour again in a couple of days and if it still does not work I am going to delete this endpoint.

Using POST is a different endpoint. This is going to create a new thread instead of listing them. Therefore you get the attributes from a single thread and not a thread list.

gehrisandro commented 7 months ago

Hi @vesper8

I have removed the threads list endpoint for now.