AntFleet

Disagreement · 8ff8c1af-openai-5

Token usage estimation in OpenAI provider ignores system prompt, undercounting input tokens

solo GPT-5
repo 56f59a0d·PR #2·reviewed 4 days ago

GPT-5 finding

Token usage estimation in OpenAI provider ignores system prompt, undercounting input tokens

lowmaintainabilityhigh
  • src/providers/openai.ts:154-157
  • src/providers/openai.ts:231-233
Both streaming and non-streaming estimations exclude the system prompt text, which can be large and materially affect cost tracking. This under-reports input tokens when the API does not return exact usage.

Recommendation

Include options.systemPrompt.length in the estimation. For example: baseLength = (options.systemPrompt?.length ?? 0) + messages.reduce(...); Then divide by an appropriate chars-per-token heuristic per model.

Other reviewer

The other reviewer flagged nothing in this file/line range.

Why this didn't post

This finding didn't meet AntFleet's unanimous agreement threshold. Both frontier models review every PR independently; only findings they both flag with the same severity and category are posted to the PR. This one fell through.

read the methodology →

From the same review

These findings passed the unanimous gate on the same PR review. The disagreement above was filtered out; the findings below were posted.