PDF text increases prompt usage but not count_tokens on gemini-4-hydrogen
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 42/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- google-cloud, python
- Domínio
- backend-api-design
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 4.1k
- Forks
- 1.1k
- Merge médio
- 2d 15h
- PRs com merge (30d)
- 97
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de googleapis/python-genai
-
Interactions retries ignore the documented `initial_delay` and `max_delay` defaultsTalvez já em andamento @Venkaiahbabuneelam assumiu há 8 dias. Abertapriority: p2 status:awaiting user response type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
googleapis/python-genai#3317 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Test import module that doesn't existTalvez já em andamento @Venkaiahbabuneelam assumiu há 34 dias. Abertapriority: p2 type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
googleapis/python-genai#3122 · 6 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Curated history keeps half a user turn when the model turn is invalidTalvez já em andamento @Venkaiahbabuneelam assumiu há 43 dias. Abertapriority: p2 type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
googleapis/python-genai#3051 · 3 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFCTalvez já em andamento @Venkaiahbabuneelam assumiu há 43 dias. Abertapriority: p2 type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
googleapis/python-genai#3044 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Structured-output continuation merge raises AttributeError: __pydantic_generic_metadata__ when a hop has parsed JSONTalvez já em andamento @Venkaiahbabuneelam assumiu há 6 dias. Abertapriority: p2 type: bug
googleapis/python-genai#3350 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de googleapis/python-genai
Issues semelhantes
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 76/100
samuelclay/NewsBlur#2214 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
MODEL_NOT_FOUND gives no suggestion for a model listed only as model:profileTalvez já em andamento @ShaiShmuel assumiu hoje. Abertaenhancement rust
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
superlinked/sie#985 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
readthedocs/readthedocs-builder#73 ·
Mantenedores costumam responder em até 1 dia