[GH-ISSUE #2289] [Engine] Anthropic API: cache_creation_input_tokens is never reported, though every newly read token is kept #919

Closed
opened 2026-11-04 01:47:02 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @xrip on GitHub (Oct 13, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2289

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

/v1/messages never reports cache_creation_input_tokens. Every token a request reads is kept for the next request (the live session, and the conversation cache when it is on), which is what Anthropic calls a cache write. Clients that show cache writes, such as Claude Code, always see none.

Expected: Anthropic's usage splits the prompt three ways, and the three add up to the whole prompt:

  • cache_read_input_tokens: read from the cache;
  • cache_creation_input_tokens: written to the cache by this request;
  • input_tokens: neither.

Actual: message_delta's usage has input_tokens (everything read now) and cache_read_input_tokens (the reused prefix). cache_creation_input_tokens is absent, so a client fills in 0, although the tokens read now are kept and reused by the next request.

Re-test on 0.2.0-beta (f57c0adc), 2026-10-19: still the case. The tests from #2290 fail on 0.2.0-beta's serve/server.py: UsageAndStatus.test_anthropic gets input_tokens 241 where 1 is expected (all 241 newly read tokens reported as uncached input, no cache write), and RequestAccounting.test_anthropic_nonstream_classifies_only_original_input_as_cached / ..._stream_... fail the same way. With #2290's change, all of them pass.

Impact: display only; the totals and a client's context fill are already right. Claude Code's status line and cost estimate show every newly read token as uncached input, and no cache writes at all.

Fix: #2290. The newly read tokens are cache_creation_input_tokens, all but the last prompt token, which stays input_tokens (never 0: Claude Code takes 0 as "not given" and counts the prompt twice, #1013).

Reproduction status

Reproduced locally

Strata version

Strata 0.2.0-beta (f57c0adc) · engine 0.1.45.3. First seen on 0.1.43.1 with Claude Code.

Graphics card, memory and system

2x NVIDIA CMP 50HX 20 GB · 64 GB RAM · Ubuntu 24.04.4. The bug is in serve/server.py; the 0.2.0-beta re-test is the server's unit test (Windows 11, Python 3.14) and needs no GPU.

Logs

$ python -m pytest -q serve/test_server.py serve/test_parallel.py serve/test_request_accounting.py -k "cache or usage or accounting or anthropic"   # 0.2.0-beta serve/server.py
FAILED serve/test_server.py::UsageAndStatus::test_anthropic - AssertionError: 241 != 1
FAILED serve/test_request_accounting.py::RequestAccounting::test_anthropic_nonstream_classifies_only_original_input_as_cached
FAILED serve/test_request_accounting.py::RequestAccounting::test_anthropic_stream_classifies_only_original_input_as_cached
3 failed, 27 passed, 363 deselected, 16 subtests passed
Originally created by @xrip on GitHub (Oct 13, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/2289 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### What happened `/v1/messages` never reports `cache_creation_input_tokens`. Every token a request reads is kept for the next request (the live session, and the conversation cache when it is on), which is what Anthropic calls a cache write. Clients that show cache writes, such as Claude Code, always see none. **Expected:** Anthropic's usage splits the prompt three ways, and the three add up to the whole prompt: - `cache_read_input_tokens`: read from the cache; - `cache_creation_input_tokens`: written to the cache by this request; - `input_tokens`: neither. **Actual:** `message_delta`'s usage has `input_tokens` (everything read now) and `cache_read_input_tokens` (the reused prefix). `cache_creation_input_tokens` is absent, so a client fills in 0, although the tokens read now are kept and reused by the next request. **Re-test on 0.2.0-beta (`f57c0adc`), 2026-10-19:** still the case. The tests from #2290 fail on 0.2.0-beta's `serve/server.py`: `UsageAndStatus.test_anthropic` gets `input_tokens` 241 where 1 is expected (all 241 newly read tokens reported as uncached input, no cache write), and `RequestAccounting.test_anthropic_nonstream_classifies_only_original_input_as_cached` / `..._stream_...` fail the same way. With #2290's change, all of them pass. **Impact:** display only; the totals and a client's context fill are already right. Claude Code's status line and cost estimate show every newly read token as uncached input, and no cache writes at all. **Fix:** #2290. The newly read tokens are `cache_creation_input_tokens`, all but the last prompt token, which stays `input_tokens` (never 0: Claude Code takes 0 as "not given" and counts the prompt twice, #1013). ### Reproduction status Reproduced locally ### Strata version Strata 0.2.0-beta (`f57c0adc`) · engine 0.1.45.3. First seen on 0.1.43.1 with Claude Code. ### Graphics card, memory and system 2x NVIDIA CMP 50HX 20 GB · 64 GB RAM · Ubuntu 24.04.4. The bug is in `serve/server.py`; the 0.2.0-beta re-test is the server's unit test (Windows 11, Python 3.14) and needs no GPU. ### Logs ```text $ python -m pytest -q serve/test_server.py serve/test_parallel.py serve/test_request_accounting.py -k "cache or usage or accounting or anthropic" # 0.2.0-beta serve/server.py FAILED serve/test_server.py::UsageAndStatus::test_anthropic - AssertionError: 241 != 1 FAILED serve/test_request_accounting.py::RequestAccounting::test_anthropic_nonstream_classifies_only_original_input_as_cached FAILED serve/test_request_accounting.py::RequestAccounting::test_anthropic_stream_classifies_only_original_input_as_cached 3 failed, 27 passed, 363 deselected, 16 subtests passed ```
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6270928414 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Author
Owner

@xrip commented on GitHub (Oct 19, 2026):

/reopen

<!-- gh-comment-id:6274675742 --> @xrip commented on GitHub (Oct 19, 2026): /reopen
Author
Owner

@github-actions[bot] commented on GitHub (Oct 19, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6274679030 --> @github-actions[bot] commented on GitHub (Oct 19, 2026): Reopened, thank you. A maintainer will pick it up from here.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#919
No description provided.