Skip to content

fix(streaming): add null usage fallback to all providers#901

Merged
sixlive merged 1 commit intoprism-php:mainfrom
aimbit-ni:fix/streaming-null-usage-fallback
Feb 26, 2026
Merged

fix(streaming): add null usage fallback to all providers#901
sixlive merged 1 commit intoprism-php:mainfrom
aimbit-ni:fix/streaming-null-usage-fallback

Conversation

@aimbit-ni
Copy link
Copy Markdown
Contributor

Summary

  • StreamEndEvent.usage can be null when providers don't include usage data in their final stream chunk, causing a TypeError downstream (e.g. in laravel/ai)
  • Adds ?? new Usage(0, 0) fallback to emitStreamEndEvent() in all 7 providers missing it: Groq, XAI, OpenRouter, Mistral, DeepSeek, Anthropic, and Gemini
  • Matches the existing pattern already used in the OpenAI stream handler

Refs #900

Test plan

  • Full test suite passes (1361 tests, 0 failures)
  • PHPStan level 8 clean
  • Pint + Rector formatted

StreamEndEvent.usage can be null when providers don't include usage
data in their final stream chunk, causing a TypeError downstream.
Add `?? new Usage(0, 0)` fallback to emitStreamEndEvent() in all
providers missing it, matching the existing pattern in the OpenAI
stream handler.
@sixlive sixlive force-pushed the fix/streaming-null-usage-fallback branch from b98d832 to 2d2578f Compare February 26, 2026 17:05
@sixlive sixlive merged commit d6aed55 into prism-php:main Feb 26, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants