Skip to content

anthropic: report cache_read_input_tokens in /v1/messages usage#1

Open
aeon-x wants to merge 1 commit into
mainfrom
feat/anthropic-cache-read-input-tokens
Open

anthropic: report cache_read_input_tokens in /v1/messages usage#1
aeon-x wants to merge 1 commit into
mainfrom
feat/anthropic-cache-read-input-tokens

Conversation

@aeon-x

@aeon-x aeon-x commented May 27, 2026

Copy link
Copy Markdown
Owner

Summary

The /v1/messages (Anthropic Messages API) response omits prefix-cache
accounting. AnthropicUsage already declares cache_read_input_tokens,
and the underlying ChatCompletionResponse carries the count in
usage.prompt_tokens_details.cached_tokens (populated when
--enable-prompt-tokens-details is set), but the converter never copies
it across — so clients always see cache_read_input_tokens: null even on
a warm prefix-cache hit. /v1/chat/completions reports it correctly for
the same request; this brings /v1/messages to parity.

Changes

  • messages_full_converter (non-streaming): map
    prompt_tokens_details.cached_tokenscache_read_input_tokens.
  • streaming message_start usage: same mapping, guarded so it stays
    None when token details aren't present (no behavior change when the
    detail is unavailable).

Verification

On a deployed runtime (Qwen3-Coder-30B, --enable-prompt-tokens-details
already set), a warm identical prompt returns:

  • /v1/chat/completionsprompt_tokens_details.cached_tokens: 2800
  • /v1/messages (before) → {input_tokens, output_tokens} only
  • /v1/messages (after) → includes cache_read_input_tokens

Test plan

  • Warm a prefix, hit /v1/messages non-streaming, confirm cache_read_input_tokens is populated
  • Same for streaming (message_start event usage)
  • Cold request still reports cache_read_input_tokens: null (or 0), no regression

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant