PDF text increases prompt usage but not count_tokens on gemini-4-hydrogen
维护者通常 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 APIthinking_level=LOW; no system instruction, tools, or response schema
Steps to reproduce
- Extract the attached pdf-token-repro.zip.
- 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:
| 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/python-genai 的其他 Issue
-
Interactions retries ignore the documented `initial_delay` and `max_delay` defaults可能已有人在做 @Venkaiahbabuneelam 于 8 天前认领。 未关闭priority: p2 status:awaiting user response type: bug
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/python-genai#3317 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Test import module that doesn't exist可能已有人在做 @Venkaiahbabuneelam 于 34 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 66/100
googleapis/python-genai#3122 · 6 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Curated history keeps half a user turn when the model turn is invalid可能已有人在做 @Venkaiahbabuneelam 于 43 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 62/100
googleapis/python-genai#3051 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFC可能已有人在做 @Venkaiahbabuneelam 于 43 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 82/100
googleapis/python-genai#3044 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Structured-output continuation merge raises AttributeError: __pydantic_generic_metadata__ when a hop has parsed JSON可能已有人在做 @Venkaiahbabuneelam 于 6 天前认领。 未关闭priority: p2 type: bug
googleapis/python-genai#3350 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 googleapis/python-genai 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
readthedocs/readthedocs-builder#73 ·
维护者通常 1 天内回复
-
area: ci bug good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
hffgzktbcc-blip/ounce-core#484 · 1 条评论 ·
维护者通常 1 天内回复
-
bug documentation
难度 2/5 1-3 小时 新手友好度 73/100
vllm-project/vllm-torchtpu#3395 ·
维护者通常 1 天内回复
-
Hermes plugin: MITM-domain discovery misses the model: block (provider/base_url nested under model:) — traffic blind-tunnels silently, zero compression可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 66/100
ranxianglei/billion-context#7063 ·
维护者通常 1 天内回复