Google LLM plugin leaves Gemini thinking tokens out of completion_tokens

Đã đóng
#7,889 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@ninglinLiu đang làm issue này rồi.

Từ ngày 17/10/2026.

  • #7891 của @ninglinLiu — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start in livekit/plugins/google/llm.py and inspect how CompletionUsage is built from usage_metadata; compare with the reasoning-token handling mentioned in realtime_api.py and issue #7326. Reproduce the supplied usage chunk and check that completion and reasoning tokens match the expected values; pull request #7891 is already open for this issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Description

For Gemini thinking models (2.5, 3), usageMetadata reports the answer tokens (candidatesTokenCount) and the thinking tokens (thoughtsTokenCount) separately. Both are billed as output, and totalTokenCount includes both.

livekit-plugins-google's LLM (livekit/plugins/google/llm.py, the CompletionUsage built from usage_metadata) sets completion_tokens = candidates_token_count and doesn't set reasoning_tokens. CompletionUsage documents reasoning_tokens as "already counted in completion_tokens". So with thinking on:

  • completion_tokens under-reports output,
  • reasoning_tokens is 0,
  • prompt_tokens + completion_tokens != total_tokens.

Usage metrics and any cost computed from completion_tokens come out low.

#7326 adds reasoning tokens for the Gemini Live RealtimeModel (realtime_api.py). This is the same gap in the non-realtime LLM.

Expected Behavior

completion_tokens = candidates_token_count + thoughts_token_count and reasoning_tokens = thoughts_token_count, matching how CompletionUsage defines them and how the OpenAI-compatible path reports completion_tokens_details.reasoning_tokens.

Reproduction Steps

google.LLM(model="gemini-2.5-flash", api_key=..., http_options=types.HttpOptions(base_url=<local server>)) against a server that streams one chunk with:

"usageMetadata": {"promptTokenCount": 10, "candidatesTokenCount": 5, "thoughtsTokenCount": 40, "totalTokenCount": 55}

The usage chunk is completion_tokens=5 reasoning_tokens=0 total_tokens=55 (expected completion_tokens=45 reasoning_tokens=40).

Package Versions

livekit-agents and livekit-plugins-google from main (f548149).

This issue was drafted with Claude Code; the reproduction above was run on main to confirm the output.

Ngôn ngữ chính
Python
Star
14.6k
Fork
3.9k
Merge trung bình
2 ngày 20 giờ
Pull request đã merge (30 ngày)
248

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của livekit/agents

Tất cả issue của livekit/agents

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.