Skip to content

Account for image inputs in LLM gateway token estimates #1316

Description

@barrygreengus

Problem

The LLM API gateway does not estimate image input tokens from image dimensions
and the target model's visual processor. Multimodal requests can therefore
reserve input-token capacity based on serialized payload size rather than the
visual tokens consumed by inference.

Desired behavior

  • Read dimensions from base64-encoded image headers without decoding pixels.
  • Bound header inspection so malformed images cannot cause unbounded scans.
  • Apply model-specific patch, tile, and fixed-token estimators where known.
  • Use a conservative fallback for unknown models or unavailable dimensions.
  • Keep model-name matching explicit so unrelated names cannot select a cheaper
    estimator.

Acceptance criteria

  • Chat Completions and Responses admission accounting includes every image.
  • Common NIM vision models use documented processor equations.
  • Unknown models receive a size-based bounded estimate.
  • PNG, JPEG, GIF, and WebP base64 inputs are covered by tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions