这是indexloc提供的服务,不要输入任何密码
Skip to content

Realtime metrics collection throws error when token_count is None #2349

@fredvollmer

Description

@fredvollmer

We are using the Gemini Realtime model. After upgrading to 1.0.21, we started seeing the following error immediately proceeding any function_tool invocation:

2025-05-21 13:40:42,333 - ERROR livekit.plugins.google - error in receive task: unsupported operand type(s) for +=: 'int' and 'NoneType' 
Traceback (most recent call last):
  .\livekit\plugins\google\beta\realtime\realtime_api.py", line 571, in _recv_task
    self._handle_usage_metadata(response.usage_metadata)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  .\livekit\plugins\google\beta\realtime\realtime_api.py", line 822, in _handle_usage_metadata
    **_token_details_map(usage_metadata.response_tokens_details),
      ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 .\livekit\plugins\google\beta\realtime\realtime_api.py", line 793, in _token_details_map
    token_details_map["audio_tokens"] += token_detail.token_count
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

This error is caused by token_detail.token_count being None in the usage metadata returned by the model.

I believe this was introduced in #2275.

A simple fix is ensure token_count is defined before attempting to update the token_details_map. I'll open a PR to this effect, but if there's a deeper cause/better fix please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions