Skip to content

API: Add opt-in /metrics endpoint with live generation counters - #510

Merged
turboderp merged 1 commit into
theroyallab:mainfrom
blaakstone:feature/live-metrics
Nov 1, 2026
Merged

turboderp merged 1 commit into
theroyallab:mainfrom
blaakstone:feature/live-metrics

Conversation

@blaakstone

Copy link
Copy Markdown
Contributor

Is your pull request related to a problem? Please describe.
The /metrics endpoint in #443 accumulates its counters from the backend's
finish chunk, so tabbyapi:tokens_predicted_total and
tabbyapi:tokens_predicted_seconds_total only move when a request completes.
During a long generation a scraper sees nothing for tens of seconds and then a
single step, which leaves a throughput graph with nothing to plot.

This adds the same endpoint with those counters written as each piece is
delivered to the client, so they move while the model is generating.

Why should this feature be added?
Live throughput is what a dashboard wants. llama.cpp and vLLM update their
token counters while a request is in flight, so a dashboard polling a mixed
deployment shows a flat line for tabbyAPI until each request ends. The endpoint
stays opt-in (network.enable_metrics, off by default, no API key required,
like /health). When it is off, the generation loop skips the per-piece calls:
the only cost on a request is one config read.

Examples
One 2000-token streaming completion, polled every 2 s:
tokens_predicted_total went 142 → 411 → 685 → 940 → 1167 → 1378, with
predicted_tokens_seconds at 120-130 tokens/s and requests_processing at 1
throughout. rate(tabbyapi:tokens_predicted_total[10s]) therefore shows the
generation while it runs instead of one step afterwards.

Checked against the responses: for a 500-token completion the counter moved by
exactly 500, and four queued 300-token completions moved it by 1200. With MTP
speculative decoding (6 draft tokens) the counters reported 3042 drafted, 1006
accepted and 507 decode steps. With max_batch_size: 1, four simultaneous
requests showed requests_processing 1 / requests_deferred 2 while queued,
and 0 / 0 once drained. Disabled, the endpoint answers 404 with a message naming
the option.

Additional context
Builds on #443 by klement: the option name, the endpoint path, the
404-when-disabled behaviour, and the metric names and help text are the same, so
a scraper written for that PR works unchanged. This is a stand-alone subset (the
inference counters only: no KV-cache, offload, recurrent-cache or histogram
metrics) and does not depend on #443. If both land, the two common/metrics.py
need reconciling; the per-piece calls here can be carried over to #443.

Generation tokens are counted as they are delivered (len(token_ids) of each
piece, on a per-request clock), not read from the engine's new_tokens on the
finish chunk. This stays correct when one piece carries several tokens (the
streaming merge from #450), but the total can differ by a token from the
engine's own tally.

Tested with pytest tests/test_metrics.py tests/test_metrics_endpoint.py
(9 tests, no GPU), and on a 27B EXL3 model on a single RTX 5090, including a
dashboard (llm-visuals with a tabbyAPI adapter) that now shows throughput during
the generation. Not covered: the cancellation path. In my test, killing the
client did not stop the generation, so the request still finished and was
counted.

formatting.sh currently exits early on main: it checks ruff's version
against requirements-dev.txt, which is no longer in the repository. This PR
was formatted with ruff format and ruff check directly (the version pinned
in pyproject.toml).

Written with the help of a language model, reviewed and tested on real hardware.

@blaakstone blaakstone mentioned this pull request Oct 29, 2026
Generation counters advance as each piece is delivered to the client, on a
per-request clock, so a scraper sees throughput while a request runs. Same
option, endpoint and metric names as theroyallab#443. Off by default; when off, the
generation loop makes no metrics calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blaakstone
blaakstone force-pushed the feature/live-metrics branch from 26e0f00 to 04c4643 Compare October 30, 2026 20:35
@turboderp
turboderp merged commit 8ddf885 into theroyallab:main Nov 1, 2026
1 check passed
@blaakstone
blaakstone deleted the feature/live-metrics branch November 2, 2026 04:48
DingoOz pushed a commit to DingoOz/llm-visuals that referenced this pull request Nov 25, 2026
TabbyAPI (ExLlamaV2/V3) was only named in the keyword list, with no live
numbers. Since theroyallab/tabbyAPI#510 it serves an opt-in Prometheus
/metrics (network.enable_metrics) with llama.cpp-style names under a
tabbyapi: prefix.

Detect `python main.py` / `start.py` launches that name tabby or exllama,
read the port, host, model name and max_seq_len from the YAML --config
(port 5000 otherwise), and recognise the tabbyapi: samples behind
--endpoint. Map the counters onto the shared vLLM adapter: prompt,
cached and generated tokens, requests in flight, TTFT, server-measured
decode time and the draft counters, with the draft depth taken as
drafted tokens per verify step. The cached and verify-step counters
also accept the names of an earlier draft of the endpoint.

Tested on an RTX 5090 against tabbyAPI main with ExLlamaV3 and MTP:
live decode, depth 6, acceptance matching the server's own figure.
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.

2 participants