You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: MistralAIChatCompletion sets metadata['usage'] to a tuple, so usage is missing from telemetry #14617
In the Python MistralAIChatCompletion connector, metadata["usage"] is set to a one-element tuple instead of a CompletionUsage, because of a trailing comma (mistral_ai_chat_completion.py#L254-L259):
the telemetry decorator only records token usage when isinstance(usage, CompletionUsage) (decorators.py#L422-L427), so Mistral chat spans carry no gen_ai.usage.input_tokens / gen_ai.usage.output_tokens;
user code that reads result.metadata["usage"].prompt_tokens (as it does for the other connectors) raises AttributeError: 'tuple' object has no attribute 'prompt_tokens'.
Expected behavior
metadata["usage"] is a CompletionUsage, as in the OpenAI, Google, Bedrock and Ollama connectors.
Fix
Remove the trailing comma (the outer parentheses then become a plain grouping).
Found by reading the code while checking how connectors report usage to telemetry; it was not run against the Mistral API here. This report was drafted with Claude Code.
Activity