Skip to content

[Feature]: Expose image and video prompt-token counts in trtllm-serve responses #19460

Open

Description

@dev-adas

🚀 The feature, motivation and pitch

Please expose per-request image and video prompt-token counts in the OpenAI-compatible /v1/chat/completions response from trtllm-serve.

Clients need to distinguish text and visual contributions to the prompt for usage accounting, benchmarking, and diagnosing missing multimodal input. Aggregate prompt_tokens cannot provide that breakdown. These counts would describe input processing, not establish that the model correctly understood the media.

In v1.3.0rc27, PromptTokensDetails contains only cached_tokens. The Qwen processor already computes video-token counts from processed video_grid_thw in get_num_tokens_per_video, but that information is not exposed in response usage.

One possible response shape is below. The values are illustrative, not measured output:

{
  "usage": {
    "prompt_tokens": 1242,
    "completion_tokens": 45,
    "total_tokens": 1287,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "image_tokens": 0,
      "video_tokens": 1024
    }
  }
}

Suggested initial scope:

  • Support Qwen image/video inputs first, with optional fields that can accommodate other supported processors later. Field names are open to maintainer guidance.
  • Derive counts from the actual processed media used by the request, after sampling/resizing, without another media decode or preprocessing pass. Define visual tokens as the embedding positions contributed to the language-model prompt; exclude framing tokens.
  • Keep prompt totals unchanged: visual counts are a breakdown, not additional tokens. Preserve counts when cached media/context is reused; these describe prompt contents rather than newly performed computation.
  • Omit unavailable counts; reserve zero for a known zero. Do not estimate counts from video duration or a successful URL fetch.
  • Return consistent details in non-streaming responses and streaming usage chunks when usage is requested, including the postprocessing-worker path.

Alternatives

Aggregate prompt counts do not distinguish text from visual tokens. Client-side estimates can disagree with server sampling and resizing. Server logs or aggregate metrics are useful for debugging but do not provide accounting attached to an individual API response.

Additional context

This is a proposal based on upstream source inspection, not a claim of a reproduced GPU failure. The existing cached-token reporting contribution provides a related response-metadata precedent.

I would be happy to contribute an implementation and tests after maintainers agree on the response shape and counting semantics. Suggested coverage includes text-only, image, video, unavailable accounting, cache reuse, and streaming/non-streaming parity. Any disaggregated-serving scope should be explicit so counts are not silently lost at a handoff.

Would this be an acceptable initial scope, and is there an existing preferred format for per-modality usage?

Before submitting a new issue...

  • Searched existing issues and pull requests, and checked the public multimodal documentation and examples.

Activity

  1. added
    Multimodal
    on Sep 20, 2026
  2. added a commit that references this issue on Sep 22, 2026
  3. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Multimodal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions