Skip to content

[REQUEST] Expose llama.cpp-style top-level timings and cached/draft token stats in OAI responses #454

Description

@dfein38347g

(Drafted with AI assistance.)

When consuming tabbyAPI behind a metrics-aware proxy (e.g. llama-swap), per-request speed and cache stats don't surface, because the stats live only in the non-standard usage object while the standard places consumers look are empty.

Problem

  1. Speeds are only in usage. UsageStats carries prompt_tokens_per_sec / completion_tokens_per_sec, but there is no top-level timings (llama.cpp-style) or metrics (vLLM-style) object. Consumers that read top-level timings/metrics for prompt/prediction speed show "unknown" even though token counts populate.
  2. Cached prompt tokens are dropped. The backend (exllamav3) finish chunk already reports cached_tokens, but get_usage_stats discards it when building UsageStats, so the OpenAI-standard usage.prompt_tokens_details.cached_tokens is never emitted.
  3. Spec-decoding draft stats are dropped. The finish chunk carries draft_accept / draft_reject, but they are not surfaced anywhere in the response.
  4. Prompt count/speed mismatch. usage.prompt_tokens reports the total (including cached), while prompt_tokens_per_sec is computed over new tokens only — so the count and the speed disagree.

This is solvable and is working for us. We run a patched tabbyAPI image that exposes these fields, and the metrics populate correctly in our setup. We have a working patch set against v1.4.2 that we're happy to share for reference; we're not asking to own the implementation.

General direction for a fix

  • Emit a top-level timings object on /chat/completions and /completions (streaming + non-streaming) with llama.cpp-compatible keys: prompt_n, prompt_per_second, predicted_n, predicted_per_second, and draft_n / draft_n_accepted when spec-decoding is active.
  • Add prompt_tokens_details: {cached_tokens} to UsageStats, populated from the backend finish chunk's cached_tokens.
  • Add draft_tokens / draft_tokens_accepted to UsageStats from draft_accept / draft_reject.
  • Decide on prompt_tokens semantics: report new-only (total − cached) to match llama.cpp, or keep total and document it.

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