Skip to content

fix(vertex_ai): map billableCharacterCount to usage.prompt_tokens_details.character_count - #46008

Closed
Mrun25 wants to merge 5 commits into
BerriAI:mainfrom
Mrun25:fix-vertex-embeddings-billable-chars
Closed

Mrun25 wants to merge 5 commits into
BerriAI:mainfrom
Mrun25:fix-vertex-embeddings-billable-chars

Conversation

@Mrun25

@Mrun25 Mrun25 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

TLDR

Problem: Vertex text embedding predict responses carry the billable unit for per-character-priced models (text-embedding-005, gemini-embedding-001, text-multilingual-embedding-002) as top-level metadata.billableCharacterCount, but transform_vertex_response_to_openai only sums predictions token_count into usage.prompt_tokens and discards metadata - callers can't see what they're billed for.
Fix: map metadata.billableCharacterCount to usage.prompt_tokens_details.character_count (the field already exists on PromptTokensDetailsWrapper and is used by the Vertex multimodal embeddings path). Responses without metadata are unchanged.

Fixes #45999

Testing

  • New tests/unit/llms/vertex_ai/vertex_embeddings/test_transformation.py: the reporter's exact response shape now maps character_count=21 (fails on main), and the no-metadata response keeps prompt_tokens_details=None.
  • Vertex embeddings shards green (152 tests incl. multimodal + BGE).
  • ruff check, type_discipline_gate, ruff_strict_gate, test_quality_gate all pass.

Type

  • Bug fix

(Prepared with AI assistance; I reproduced the bug, wrote the fix and tests, and ran them myself.)

@codspeed

codspeed Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing Mrun25:fix-vertex-embeddings-billable-chars (40c537d) with main (ac98cab)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (102619d) during the generation of this report, so ac98cab was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

Main already maps billableCharacterCount to usage character_count through #47460, so closing this. Reopen if something is missing

@mateo-berri mateo-berri closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Vertex AI text embeddings drop metadata.billableCharacterCount

2 participants