langchain
e91da86e - feat(openrouter): add streaming token usage support (#35559)

Commit
191 days ago
feat(openrouter): add streaming token usage support (#35559) Streaming token usage was silently dropped for `ChatOpenRouter`. Both `_stream` and `_astream` skipped any SSE chunk without a `choices` array — which is exactly the shape OpenRouter uses for the final usage-reporting chunk. This meant `usage_metadata` was never populated on streamed responses, causing downstream consumers (like the Deep Agents CLI) to show "unknown" model with 0 tokens. ## Changes - Add `stream_usage: bool = True` field to `ChatOpenRouter`, which passes `stream_options: {"include_usage": True}` to the OpenRouter API when streaming — matching the pattern already established in `langchain-openai`'s `BaseChatOpenAI` - Handle usage-only chunks (no `choices`, just `usage`) in both `_stream` and `_astream` by emitting a `ChatGenerationChunk` with `usage_metadata` via `_create_usage_metadata`, instead of silently `continue`-ing past them
Author
Parents
Loading