[Bugfix][Responses API] Complete cache-write token accounting (#60973)

Signed-off-by: Kay Yan <kay.yan@daocloud.io>
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Kay Yan
2026-10-10 09:08:36 +00:00
committed by GitHub
co-authored by Codex
parent a98247ab4d
commit c41b2639e2
4 changed files with 34 additions and 2 deletions
@@ -169,6 +169,7 @@ def _make_request_output(
text: str = "Hello, world!",
token_ids: Sequence[int] = (1, 2, 3),
finish_reason: str = "stop",
num_cache_creation_tokens: int | None = None,
) -> RequestOutput:
return RequestOutput(
request_id="test",
@@ -186,6 +187,7 @@ def _make_request_output(
)
],
finished=True,
num_cache_creation_tokens=num_cache_creation_tokens,
)
@@ -425,6 +427,14 @@ def test_reasoning_tokens_counted_per_round():
assert ctx.num_reasoning_tokens == 3
def test_cache_creation_tokens_counted_per_round():
ctx = _make_context(None)
for count, expected in [(None, 0), (0, 0), (3, 3), (4, 7)]:
ctx.append_output(_make_request_output(num_cache_creation_tokens=count))
assert ctx.num_cache_creation_tokens == expected
def test_reasoning_tokens_zero_without_parser():
ctx = _make_context(None)