Skip to content

Groq streaming: ToolCall construction crashes when tool call ID is null in stream delta #966

@rezaulhreza

Description

@rezaulhreza

Description

When using the Groq provider with streaming enabled and tool calling, mapToolCalls() in Stream.php can crash with:

ToolCall::__construct(): Argument #1 ($id) must be of type string, null given

This happens because Groq's streaming API sometimes sends tool call deltas where the id field is null. The ID arrives in an earlier chunk and is not repeated in subsequent argument chunks.

Current behaviour

return new ToolCall(
    data_get($toolCall, 'id'),   // can be null for streaming deltas
    data_get($toolCall, 'name'),
    $arguments,
);

ToolCall::__construct() requires $id to be a non-null string, so this throws a TypeError and the entire streaming response fails.

Expected behaviour

The handler should either accumulate streaming deltas before constructing ToolCall objects, or use a stable fallback ID when the delta does not include one.

Steps to reproduce

  1. Configure Groq as your provider.
  2. Define one or more tools on your agent.
  3. Send a message that triggers tool use.
  4. Observe the TypeError in the streaming response.

Environment

  • prism-php/prism v0.99.22
  • Provider: Groq (streaming)
  • PHP 8.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions