Skip to content

[Bug]: Claude Models not working with Stream Option #555

@gruzker

Description

@gruzker

Description

Error when trying to use Claude with streaming.

Undefined array key "choices"

vendor\openai-php\client\src\Responses\Chat\CreateStreamedResponse.php :44

  | */
-- | --
  | public static function from(array $attributes): self
  | {
  | $choices = array_map(fn (array $result): CreateStreamedResponseChoice => CreateStreamedResponseChoice::from(
  | $result
  | ), $attributes['choices']);
  |  
  | return new self(
  | $attributes['id'] ?? null,
  | $attributes['object'],
  | $attributes['created'],
  | $attributes['model'],
  | $choices,

Steps To Reproduce


$client = OpenAI::factory()
->withApiKey($apiKey)
->withBaseUri('https://api.anthropic.com/v1')
->make();

$stream = $client->chat()->createStreamed([
'model' => 'claude-3-7-sonnet-20250219',
'messages' =>['role' => 'user', 'content' => 'Hello!'],
]);

foreach($stream as $response){
$this->stream(to: 'answer', content: $response->choices[0]->delta->content);
}
}

OpenAI PHP Client Version

^0.10.3

PHP Version

8.2

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Non-OpenAI ModelNot an OpenAI Model.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions