PDF text increases prompt usage but not count_tokens on gemini-4-hydrogen

未關閉
#3,379 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
42/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
google-cloud, python

研究方向

Start with the attached pdf_token_repro.py reproduction and compare the SDK's count_tokens request and response with generate_content usage for the two PDF inputs. The report does not isolate whether the discrepancy comes from the SDK or Gemini backend, so first check whether raw REST reproduces it and review the earlier linked report. Done means identifying the responsible layer and documenting or fixing how PDF text is accounted for.

由索引模型根據 Issue 內容生成。

描述

Description

Adding embedded text to a 10-page PDF substantially increases gemini-4-hydrogen's reported input usage, but its count_tokens estimate is unchanged. The comparison below uses a blank PDF with the same page count and dimensions as a control.

Observed through google-genai; I have not isolated whether the cause is in the SDK or backend, or tested raw REST. Please redirect me if another tracker is more appropriate.

Environment details
  • Python 3.12.13
  • macOS 26.5.2 (arm64)
  • google-genai==3.3.0, Gemini Developer API
  • thinking_level=LOW; no system instruction, tools, or response schema
Steps to reproduce
  1. Extract the attached pdf-token-repro.zip.
  2. Set GEMINI_API_KEY, then run:
pip install google-genai==3.3.0
python pdf_token_repro.py --pages 10

The script generates both synthetic PDFs and calls count_tokens and generate_content with identical contents for each model. No real documents or sensitive data are included.

Actual result

One run on 2026-11-16:

PDF Model count_tokens prompt_token_count TEXT
text.pdf gemini-3.8-flash 5,609 5,329 9
text.pdf gemini-4-hydrogen 5,638 14,642 9,322
blank.pdf gemini-3.8-flash 5,609 5,329 9
blank.pdf gemini-4-hydrogen 5,638 5,704 384

All four requests report 5,320 IMAGE tokens. On Hydrogen, adding PDF text increases reported usage by 8,938 TEXT tokens without changing the estimate.

Expected behavior

count_tokens should account for PDF text included in prompt usage, or document the difference and provide a supported way to estimate input usage before generation.

Earlier report with additional Gemini API and Vertex AI observations.

主要語言
Python
星號
4.1k
分支
1.1k
平均合併
2 天 15 小時
30 天內合併 PR
97

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

googleapis/python-genai 的其他 Issue

查看 googleapis/python-genai 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。