openai-php / openai-php/client

[Bug]: Undefined array key "choices" in CreateStreamedResponse.php when using createStreamed()

Open
#717 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
5.8k
Forks
679
Avg merge
19m
Merged PRs (30d)
2

Description

Description

When using createStreamed() in an environment using Symfony 6.4 and PHP 8.2.27, the iterator fails with:

Warning: Undefined array key "choices"
in vendor/openai-php/client/src/Responses/Chat/CreateStreamedResponse.php on line 45

This seems to happen even with valid requests, because AFAIK streamed SSE responses also include non-message events (e.g. [DONE], empty lines, or keep-alive comments) that don't contain a choices key.

CreateStreamedResponse::from() unconditionally accesses $attributes['choices'], causing a PHP warning.

Steps To Reproduce

Try to get a streamed response with createStreamed() using a locally running Ollama server with Open-AI compatible endpoints.

OpenAI PHP Client Version

v0.18.0

PHP Version

v8.2.27

Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in vendor/openai-php/client/src/Responses/Chat/CreateStreamedResponse.php at line 45 and inspect how CreateStreamedResponse::from() handles streamed SSE attributes. Reproduce the issue with createStreamed() against the locally running Ollama server described in the report; done means non-message events without a choices key no longer produce a warning while valid streamed responses continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.