llm-runtime-metrics (Python)
Python bindings for request metrics and Prometheus export.
Install from PyPI as llm-runtime-metrics.
Import in Python as:
import llm_runtime_metrics
The supported package root focuses on the request-metrics workflow.
S3 request-log proxy
Set s3_proxy_url to route S3 requests through an HTTP forward proxy, such as
a sidecar listening on http://127.0.0.1:3128:
factory = RequestMetricsFactory(
request_log_enabled=True,
s3=True,
s3_bucket="request-logs",
s3_region="us-east-1",
s3_proxy_url="http://127.0.0.1:3128",
)
The S3 bucket, region, signing, and endpoint remain unchanged. For HTTPS S3
endpoints, the proxy must support HTTP CONNECT. Omit s3_proxy_url for a
direct connection. compact_s3_parquet_to_local accepts the same option for
downloads. Use s3_endpoint only for an S3-compatible endpoint override.
In request-log records, model_name is stored as supplied. org_id is hashed
without a salt. provided_session_id is hashed without a salt so the same ID
has the same digest across deployments. request_log_hash_salt applies only to
the token-block hashes in total_hashes; without it, those hashes are unkeyed.
Timing, token counts, flags, and other metadata are stored as plain values.
Set component_name on RequestMetricsFactory to identify the type of
component that wrote each request log, for example "frontend" or "worker".
The library generates component_id once per process and shares it among all
factories in that process. Both fields are stored as plain text in JSON and
Parquet records; component_name is optional.
Add LLM Metrics To An Existing Prometheus Server
from prometheus_client import CollectorRegistry, start_http_server
from llm_runtime_metrics import (
REQUEST_FEATURE_IMAGE,
REQUEST_FEATURE_TOOLS,
RequestMetricsCollector,
RequestMetricsFactory,
)
# Reuse your existing registry if you already have one.
registry = CollectorRegistry()
factory = RequestMetricsFactory(
request_log_enabled=False,
metric_prefix="llm_runtime",
metrics_window_seconds=60.0,
metrics_quantiles=[0.5, 0.9, 0.99],
)
# Registers a custom collector that pulls fresh samples from `factory` at scrape time.
RequestMetricsCollector(
factory,
base_labels={"service": "text-generation", "engine": "vllm"},
registry=registry,
)
# If your app already exposes /metrics, wire this into that server instead.
start_http_server(8000, registry=registry)
# Example lifecycle hooks in your inference code:
def on_request_start(prompt_token_ids: list[int]):
features = REQUEST_FEATURE_TOOLS | REQUEST_FEATURE_IMAGE
return factory.new_request(prompt_token_ids, features=features)
def on_stream_step(req_metrics, full_output_token_ids: list[int], cached_tokens: int | None):
# Use `is_diff=False` when passing cumulative token ids.
req_metrics.record_tokens(full_output_token_ids, cached_tokens=cached_tokens, is_diff=False)
def on_request_success(req_metrics):
req_metrics.success()
def on_request_cancel(req_metrics):
req_metrics.cancel()
The exported request latency distributions include request_metrics_ttft_ms,
request_metrics_time_to_fifth_token_ms,
request_metrics_first_to_fifth_token_itl_ms, and request_metrics_itl_ms.
request_metrics_time_to_fifth_token_ms is the elapsed time from request start
until the fifth output token is observed by record_tokens.
request_metrics_first_to_fifth_token_itl_ms is the elapsed time between
observing the first and fifth output tokens.
Request logs include mean_output_tokens_per_step: output tokens divided by the
number of nonempty record_tokens updates. It is null when no output tokens were
recorded. One update is the observed step; callers that batch multiple engine
iterations into one update get tokens per update, not tokens per engine iteration.
The inflight gauges also include early-decode pressure between the first and
fifth output token:
current_inflight_first_to_fifth_token_requests,
mean_inflight_first_to_fifth_token_requests,
current_inflight_first_to_fifth_token_input_tokens, and
mean_inflight_first_to_fifth_token_input_tokens. The input-token gauges count
prompt tokens attached to requests that have emitted at least one output token
but have not emitted their fifth token yet.
Available request feature bits:
REQUEST_FEATURE_NONEREQUEST_FEATURE_XGRAMMARREQUEST_FEATURE_TOOLSREQUEST_FEATURE_IMAGE
If you need plain text output instead of a collector, call:
text = factory.prometheus_strfmt({"service": "text-generation", "engine": "vllm"})
Release files for llm-runtime-metrics 0.0.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llm_runtime_metrics-0.0.19.tar.gz | 104.6 kB | Details |
Built distributions (wheels)
Total release size: 144.1 MB
Release files / llm_runtime_metrics-0.0.19.tar.gz
| Download URL | llm_runtime_metrics-0.0.19.tar.gz |
|---|---|
| Size | 104.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0b1387f418386a259acc31771d12e230d7d12e879f64508f2f2f01d43e80372
|
|
BLAKE2b-256 checksum How to use checksums |
0a79b76dbd9776a1b9f8fe7d143481e32cfdc0d87907f1e2052ce174a1b3d37b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_x86_64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
32036e03504af182d88d7ce8a03738a14fba7be9dc9007f1ab3558e2b6efcb8a
|
|
BLAKE2b-256 checksum How to use checksums |
1e79bb56e86e4255e8c8bb54d59f9e705760d8b694cb2054a652b732954d5da0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_i686.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_i686.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
612a3c0b6da190a8e8c45932d32ba8b3b4ef6d44c0a505dd7b43ef7377be1307
|
|
BLAKE2b-256 checksum How to use checksums |
5d0aa3b3117d176541e4c91e61afe74a4fbe8e56411191b961c329c11bfa0c3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_armv7l.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARMv7l |
|
SHA-256 checksum How to use checksums |
b405a99b7a5d904ec996f97b4da081e07681218ff3464ede65678363a81c56f0
|
|
BLAKE2b-256 checksum How to use checksums |
9bda42595d33b0a85a868f0834066001bd19ce85ce51729d82e620c346e2d933
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_aarch64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 7.0 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
57ca7f51e2bc528978e2026b8ca4cc7b3902c88b3eb3f26e990d88bf071de681
|
|
BLAKE2b-256 checksum How to use checksums |
622a42b33a3f212ad8145879243e31becfdb467ab0b1e7f80865b9e7f05283a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 6.6 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
9996f6bc02c1a816dad34f020085d5b2183f0555b5c23d7612b293d644b7f0b3
|
|
BLAKE2b-256 checksum How to use checksums |
abc96c79fd5b747c74cb61b35c6bc3bf9c5c968f5dca3d95ca3b43f20cba37cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 8.3 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ PowerPC 64-le |
|
SHA-256 checksum How to use checksums |
79a2f39a734b491fd70777899942149741699bf43c582f6475b6a95bb69edf26
|
|
BLAKE2b-256 checksum How to use checksums |
d1673b23bc0d74c49ff0fdb6c3915c47f8d269cf81aaba471b36044f405176ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
957edb29f78d89ca8c38542f081320d4d52a4a4dc4f254e7b924d6931c20dd91
|
|
BLAKE2b-256 checksum How to use checksums |
48ac9170d20b15b2d81953174eda06bbdb535342bbad5ebd8ab913f9cece1d37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e2bb6a59ad2e086f014a66dfc91039b30debf614eb120db3eb06273deb42ba67
|
|
BLAKE2b-256 checksum How to use checksums |
268d00a106a2c8b4570f54a29c6acadfc4ec4b89141f8875cc7f755236f44d70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
b6780f702c1aceaa38eade795d49c3aadac4b485371e527f3c195688c0d0e593
|
|
BLAKE2b-256 checksum How to use checksums |
5ef5138331f1bd23d6da7f08c64255628ece0cd1b818354c72a3e6209f084245
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-win_amd64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
337610cf1b332aaed3d05a3d2339ee868c00d0512dd1a0daee6849ea9e56957a
|
|
BLAKE2b-256 checksum How to use checksums |
fd2b5e157cac0d55c9ba4de8cdf98beb1d4d8793378b55d9855f6529b8f2fb29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ebb58378135374c78e2f900871ed4296c0c9f973c8a5c2a7aa0a970cd5abfda9
|
|
BLAKE2b-256 checksum How to use checksums |
d25f538595349feecb8f8c6c0a62f100d25a91506f3d2d87ba45ef2eab9e6a34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_i686.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
558f050f95ef7304513d88ffa985c1c1cbcc940a4926695fe1b5bccc884ada5d
|
|
BLAKE2b-256 checksum How to use checksums |
11ec4e7c999f0944ef20d9562b244d4fa7ef44a3e4c5bdbe6f7dda0dc1514215
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_armv7l.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
170b5bf460135f4c26178a5f7a1fad94c4213e5343538b732000edde74b82a96
|
|
BLAKE2b-256 checksum How to use checksums |
b982159a859976d1f4d186439df73c5a563d510b35bb6f5264a4362728ec85b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 7.0 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ad34cf9abdb2bc64c1e8c8b8dfe639bbf756f4a6f635c30fffe4a8b25fe75842
|
|
BLAKE2b-256 checksum How to use checksums |
4c0e417364a40974fb09b1b06103a79d51fa894fda25634b3a4c05a86eda4cec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_28_ppc64le.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_28_ppc64le.whl |
|---|---|
| Size | 8.3 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
f0eda1031c50a40bf5daeb6c1773a840aa18e5c8371e2939d0b6dd8eab60e6e4
|
|
BLAKE2b-256 checksum How to use checksums |
009aef5960ea8134d956fa63f477116fe2e6102a925b205c0b670bb1f2e9ea79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_28_armv7l.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_28_armv7l.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
14ae073670bfc3152378daa221398bf9768fb41b1be9e0bf258b5cc83e8f53f8
|
|
BLAKE2b-256 checksum How to use checksums |
ae0e1e86498e34045966f26c7fb179d4bf0b226635a8767ed0764ffd440b879a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
21fa581158fa25d97265a64df8c017d84d65792aca26f3925750eb66e9159783
|
|
BLAKE2b-256 checksum How to use checksums |
4d7a7473b35179812fa0499c814d505318620aca3a10d94cc7a63e191af07990
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c86d5a91f354507b2d09311ae43907d5df16d8bd772f72259e96adc9d23fb2e1
|
|
BLAKE2b-256 checksum How to use checksums |
4eb12961e077cfb2d5cf97d3987714664b954afbdc8f1000a9a4774a57d5005d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
aa7ca99ad6d5932bfe41ddc43903469d1deeea7105ff5742bb0c9820089a39e5
|
|
BLAKE2b-256 checksum How to use checksums |
f1116886d4cc6fa60ba5c18107201fd75ed87be34c762a9695cb2afe26b791e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8026139c7cb6f112763f7e8494a193b5b67b84eb30ab4d75ad68249cc474cf29
|
|
BLAKE2b-256 checksum How to use checksums |
2186c8bed0c327d9dc63fa8e8d915e182be0b527e21363cf8784880b0f1cc00e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_runtime_metrics-0.0.19-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | llm_runtime_metrics-0.0.19-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
dfd09c71a2563c240e43a3e0656770bfc998ec6eae3d5c1bfd32451cc7edf452
|
|
BLAKE2b-256 checksum How to use checksums |
a7203f6f059185c9aaf2de68b1531b570d9b208dc7538acd1291cfb5cb1bd696
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|