Skip to content

[Bugfix][Frontend] Report prompt_tokens_details in batched chat completions - #64757

Merged
DarkLight1337 merged 2 commits into
vllm-project:mainfrom
Jackmeson1:fix/batch-prompt-tokens-details
Oct 31, 2026
Merged

DarkLight1337 merged 2 commits into
vllm-project:mainfrom
Jackmeson1:fix/batch-prompt-tokens-details

Conversation

@Jackmeson1

@Jackmeson1 Jackmeson1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Populate usage.prompt_tokens_details on /v1/chat/completions/batch when --enable-prompt-tokens-details is enabled, using the existing chat helper.

Claims

  • Sum cached, created-cache and multimodal counts per conversation.
  • An unknown cache count leaves its total null; disabling the flag leaves details null.
  • Reasoning-token details remain unchanged.

Validation

GPU: Colab RTX PRO 6000 Blackwell, vLLM 4e3d49dda with the precompiled wheel built at that commit, torch 2.14.0+cu132, FlashAttention 2.

python -m pytest tests/entrypoints/openai/chat_completion/test_batched_chat_completions.py -v -rA -p no:cacheprovider --timeout=900

Base with the new test: 1 failed, 11 passed (the new test, at batch_details is not None). With the fix: 12 passed.

Repro with vllm serve Qwen/Qwen2.5-0.5B-Instruct --enable-prefix-caching --enable-prompt-tokens-details (block size 16): on base the batch route returns prompt_tokens_details: null; with the fix a warm batch of two conversations returns cached_tokens: 64, where the warm single requests for the same conversations report 32 each.

pre-commit run --files vllm/entrypoints/openai/chat_completion/batch_serving.py tests/entrypoints/openai/chat_completion/test_batched_chat_completions.py docs/serving/online_serving/openai_compatible_server.md

Passed.

No model-quality evaluation: generation is unchanged.

Details

The batch generator previously constructed only usage totals. It now aggregates prompt details once per conversation.

Single chat, completions, Responses, pooling, token-in/out, Anthropic/Cohere and run-batch use other handlers; Rust returns 501 here.

Duplicate check: no open PR changes the batch usage block. I searched prompt_tokens_details, batch_serving, num_cached_tokens and chat_completion_full_generator_batch, and read the batch_serving.py hunks of the 17 open PRs that touch the file. #55120/#58116 concern completions; #61431 changes serialization; #41834 changes the sampling parameters in create_batch_chat_completion, not the usage block.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

AI disclosure: this was prepared with AI assistance (Claude Opus 5.5).

…etions

The batch chat generator built UsageInfo from aggregate token totals,
leaving prompt_tokens_details null even when enabled.

Use the existing chat helpers to aggregate cached, created-cache and
multimodal counts once per conversation. Leave a cache total null if any
conversation lacks that count. Preserve null details when disabled.

Document the behavior and test batch cache counts against the single
endpoint using the existing server fixture.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TTGAv6fe859ebbCLLfLHP
Signed-off-by: Jackmeson1 <130693642+Jackmeson1@users.noreply.github.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify

mergify Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Documentation preview: https://vllm--64757.org.readthedocs.build/en/64757/

@mergify mergify Bot added documentation Improvements or additions to documentation frontend bug Something isn't working labels Oct 30, 2026
@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. Reviewers with write access and configured trusted contributors can comment /ci run for upstream CI or /amd-ci run for AMD CI only whenever CI signals are needed.

Once the PR is approved or has the ready label, the PR author can also use the corresponding /ci run, /ci retry, and /ci cancel commands, or their /amd-ci variants. New commits do not start upstream CI automatically.

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.

🚀

@DarkLight1337 DarkLight1337 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@DarkLight1337
DarkLight1337 enabled auto-merge (squash) October 31, 2026 15:18
@DarkLight1337

Copy link
Copy Markdown
Member

/ci run

@github-actions github-actions Bot added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 31, 2026
@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #98942 for commit a85025033728.

@DarkLight1337
DarkLight1337 merged commit 0c63ce9 into vllm-project:main Oct 31, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation frontend ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants