client icon indicating copy to clipboard operation
client copied to clipboard

Response Retrieve streamed

Open boboldehampsink opened this issue 2 months ago • 8 comments

What:

  • [ ] Bug Fix
  • [x] New Feature

Description:

Adds ability to resume a background stream from a response id and cursor:

$stream = OpenAI::responses()->retrieveStreamed($rid, [
  'starting_after' => $cursor,
]);

Related:

https://platform.openai.com/docs/guides/background#streaming-a-background-response

boboldehampsink avatar Nov 11 '25 12:11 boboldehampsink

With a new method like this - I don't exactly remember it all by heart but you'll need to touch the interface, the mock and a simple test to keep the coverage.

iBotPeaches avatar Nov 11 '25 13:11 iBotPeaches

Yes this is more of a working draft now. To have discussion over I guess.

boboldehampsink avatar Nov 11 '25 13:11 boboldehampsink

@iBotPeaches improved code, added interface methods, docs and tests.

boboldehampsink avatar Nov 13 '25 09:11 boboldehampsink

Do you have any further context on the string true? I read the docs and it seems its a regular bool like the other stream endpoints. Rest looks solid - just trying to understand the string/true.

iBotPeaches avatar Nov 13 '25 13:11 iBotPeaches

Do you have any further context on the string true? I read the docs and it seems its a regular bool like the other stream endpoints. Rest looks solid - just trying to understand the string/true.

When we use the boolean it is being used as ?stream=1 instead of ?stream=true. This is because retrieve is a GET request. Apparently the OpenAI API wants this to be "true" instead of "1". It fails when passing 1 with an error message (out of the top of my head) of "cannot parse stream as boolean"

boboldehampsink avatar Nov 13 '25 13:11 boboldehampsink

We could also adjust the Payload::toRequest method to handle this, but I'm not sure if it applies to every endpoint.

boboldehampsink avatar Nov 13 '25 13:11 boboldehampsink

Also see https://www.php.net/manual/en/function.http-build-query.php#122232

boboldehampsink avatar Nov 13 '25 13:11 boboldehampsink

Ahh interesting. Thanks for all the info. Let me mess with this a bit (see impact on other endpoints, etc) and see.

iBotPeaches avatar Nov 13 '25 13:11 iBotPeaches

thanks!

iBotPeaches avatar Nov 14 '25 19:11 iBotPeaches