Both Python and TypeScript implementations are incorrectly calculating tiered pricing using an incremental model instead of the threshold (cliff) model that is the industry standard used by major providers.
When a request crosses a tier boundary, ALL tokens in that request are charged at the higher tier rate, not just the tokens above the threshold.
See for example Anthropic and Google's docs:
https://cloud.google.com/vertex-ai/generative-ai/pricing#:~:text=Grounding%20with%20your%20data,equivalent%20to%20%240.134%2Fimage%20generated.
https://platform.claude.com/docs/en/about-claude/pricing