# chunks_to_events

> **Function** in `langchain_core`

📖 [View in docs](https://reference.langchain.com/python/langchain-core/language_models/_compat_bridge/chunks_to_events)

Convert a stream of `ChatGenerationChunk` to protocol events.

Blocks are tracked independently by source-side identifier. Providers
such as Anthropic can interleave parallel tool-call chunks by index, so
each first-seen block gets a `content-block-start`, deltas keep their
stable wire index, and all open blocks are finalized at message end.
Source-side identifiers (from the block's `index` field, which may be
int or string) are translated to sequential `uint` wire indices.

## Signature

```python
chunks_to_events(
    chunks: Iterator[ChatGenerationChunk],
    *,
    message_id: str | None = None,
) -> Iterator[MessagesData]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `chunks` | `Iterator[ChatGenerationChunk]` | Yes | Iterator of `ChatGenerationChunk` from `_stream()`. |
| `message_id` | `str \| None` | No | Optional stable message ID. (default: `None`) |

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/625ed0ee8c683dd8a7d87564a14bdbd4472d2a44/libs/core/langchain_core/language_models/_compat_bridge.py#L571)