Files
chatgpt-on-wechat/models/dashscope
zhayujieandcowagent 47782ae272 feat(models): surface real provider token usage in streaming responses
Capture per-request token usage from each provider's stream and expose it
as an OpenAI-shaped usage field on a trailing chunk, so the agent can show
an accurate context-usage count instead of a char-based estimate.

- OpenAI-compatible bots (deepseek/doubao/mimo/moonshot/modelscope): request
  stream_options.include_usage and forward the trailing usage chunk.
- minimax: capture the usage it already emits on a trailing chunk.
- claude: read input_tokens (message_start) + output_tokens (message_delta)
  and emit a trailing usage chunk.
- gemini: map usageMetadata to the OpenAI usage shape.
- dashscope: map input_tokens/output_tokens onto each chunk.

Purely additive; content/tool-call parsing paths are unchanged, and unknown
stream_options are ignored by providers that do not support them.

Co-authored-by: cowagent <cow@cowagent.ai>
2026-09-06 18:31:15 +08:00
..