Repository navigation
fix(costs): count cached input tokens once - #3353
Conversation
|
Note Production impact unlikely. Checked Also considered · 4 refuted
Analysed against 5 Cloudflare Workers and 1 repository
Polylane analysed Rate this review: 👍 helpful · 👎 not helpful · 😕 confusing Previous verdicts (1)
|
There was a problem hiding this comment.
LGTM: no issues found
Reviewed at e299580.
For agents
Rationale: No findings: both OpenAI wire shapes normalize inclusive input before pricing and tier selection; provider-reported USD precedence and Anthropic accounting are preserved.
Full review
No findings: source review confirms that both OpenAI formats subtract cache reads and writes before pricing and tier selection, while preserving provider-reported USD precedence and Anthropic accounting.
e299580 to
54f2c7e
Compare
|
Addressed in 54f2c7e. Both OpenAI readers retain |
There was a problem hiding this comment.
LGTM: no issues found
Reviewed at 54f2c7e.
For agents
Rationale: No findings: both OpenAI readers preserve nonnegative input and the cache anomaly flag reaches model.turn through buffered and streamed proxy paths.
Full review
No findings in the source review: both OpenAI readers keep ordinary input nonnegative, and buffered and streamed proxy paths retain cacheOverReported: true on model.turn.
Switchboard reports the cost of agent runs. This change counts cached input once so estimates and spend gates use the correct price tier.
Why: OpenAI includes cache reads and writes in its input total. The meter kept that total as ordinary input, then charged both cache buckets again. A 146,505-token staging turn also entered the 272,000-token tier too early. See the failed staging acceptance.
Where to look
Feedback wanted: Check inclusive input normalization on both OpenAI wire shapes and confirm that provider-reported cost still takes precedence.
Risk: A wrong cache split can misstate run costs or spend gates for proxied model calls. Revert this commit to restore the prior meter. Stored historical estimates are not rewritten.
Verified: 300 focused tests, root types, scoped lint/format, specs and hygiene passed. Fresh current-head native review, CI and live acceptance remain pending.
Decisions (1)
Validation (5 criteria)
For agents
The official OpenAI prompt caching guide defines cached and cache-write input inside the inclusive input total: https://developers.openai.com/api/docs/guides/prompt-caching . Installed pi openai-responses-shared.js and openai-completions.js already subtract both buckets. The original staging gate remains red; this PR does not override it or raise the $5 cap. A cheaper recurring HTTP staging smoke model is a separate change. The first native round approved e299580. The current head adds the Polylane observability suggestion and needs fresh review. cacheOverReported is a bounded boolean; no provider text or credentials enter telemetry.
Generated with Codex.