text-embeddings-inference documentation

Prometheus metrics

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Prometheus metrics

Text Embeddings Inference (TEI) exports Prometheus metrics that you can use to monitor traffic, errors, latency and batching. This page lists every metric, where to scrape it and what it measures.

Scraping the metrics

Where the metrics are served depends on the server type and on --prometheus-port (or the PROMETHEUS_PORT environment variable):

ServerDefault--prometheus-port set to a different port than --port
HTTPGET /metrics on the API port (3000 locally, 80 in the Docker images). If --root-path is set, the route is served under that prefix.Metrics are served on the Prometheus port, and /metrics is removed from the API port and from the OpenAPI schema.
gRPCServed on port 9000.Metrics are served on the given port.

Serving HTTP metrics on a separate port requires TEI v1.10.0 or later. Earlier versions ignore --prometheus-port for the HTTP server.

For example, with the HTTP server running locally on port 8080:

curl 127.0.0.1:8080/metrics

Metric series appear when they are first recorded. A fresh server can return an empty response before inference work begins. A te_request_failure series for a given err value only appears after that failure has happened.

Serving metrics on a separate port

When --api-key is set, it only protects the inference routes: /metrics stays readable by anyone who can reach the API port. To keep the metrics off the public API port, for example behind an ingress, serve them on a dedicated port:

text-embeddings-router --model-id BAAI/bge-small-en-v1.5 --port 8080 --prometheus-port 9000
curl 127.0.0.1:9000/metrics

A separate metrics port does not add authentication. Keep it reachable only by your scraper, using a private interface or network rules. This Docker example publishes it on the host loopback interface.

volume=$PWD/data

docker run -p 8080:80 -p 127.0.0.1:9000:9000 -v "$volume:/data" --pull always \
    ghcr.io/huggingface/text-embeddings-inference:cpu-1.10 \
    --model-id BAAI/bge-small-en-v1.5 --prometheus-port 9000

Prometheus configuration

A minimal Prometheus scrape configuration:

scrape_configs:
  - job_name: text-embeddings-inference
    static_configs:
      - targets: ["127.0.0.1:8080"]  # or the value of --prometheus-port
        labels:
          model: BAAI/bge-small-en-v1.5

Use a target address that is reachable from Prometheus. 127.0.0.1 works when Prometheus runs on the TEI host; for separate containers, use the TEI service address. For shared HTTP metrics with --root-path /tei, add metrics_path: /tei/metrics to the scrape job. With a dedicated metrics port, use that port and the default /metrics path, regardless of the API root path.

TEI does not add model or route labels. Prometheus adds job and instance labels when scraping; add target labels such as model to identify the model served by each instance.

Metric names are exported exactly as listed on this page: counters have no _total suffix, and every histogram is exported as _bucket, _sum and _count series.

Request metrics

These metrics are recorded for every HTTP and gRPC route that runs the model.

MetricTypeLabelsDescription
te_request_countCountermethodNumber of requests received.
te_request_successCountermethodNumber of requests that completed successfully.
te_request_failureCountererrNumber of failed requests, by failure reason.
te_request_durationHistogramEnd-to-end time of a successful request, in seconds.
te_request_tokenization_durationHistogramTime spent tokenizing a successful request, in seconds.
te_request_queue_durationHistogramTime a successful request waited in the queue, in seconds.
te_request_inference_durationHistogramTime spent running the model for a successful request, in seconds.
te_request_input_lengthHistogramNumber of tokens in each input, after truncation.

The method label is single when the request contains one input and batch when it contains a list of inputs. /rerank requests are always counted as batch.

For batch requests, te_request_tokenization_duration, te_request_queue_duration and te_request_inference_duration record the average time per input, while te_request_duration records the total time of the request.

The err label of te_request_failure takes the following values:

errCause
validationThe request is invalid, for example the inputs are empty or dimensions is out of range.
batch_sizeThe request contains more inputs than --max-client-batch-size.
tokenizationAn input could not be tokenized, including inputs longer than the model’s maximum input length when truncation is disabled.
model_typeThe route does not match the model, for example /embed on a classification model.
overloadedThe server is already handling --max-concurrent-requests requests. HTTP clients receive a 429 status code.
inferenceThe model failed to process the input.
droppedThe client disconnected while its request was waiting in the queue.
missing_valuesgRPC only: a streaming rerank request did not return a score for every text.

Don’t compute an error ratio as te_request_failure / te_request_count: failures are counted per input and on routes that don’t increment te_request_count.

Embedding metrics

These metrics are recorded by the embedding routes: /embed, /embed_all, /embed_sparse, /embeddings, /v1/embeddings and /similarity, as well as their gRPC equivalents.

MetricTypeDescription
te_embed_countCounterNumber of inputs sent for embedding.
te_embed_successCounterNumber of inputs embedded successfully.
te_embed_durationHistogramEnd-to-end time to embed one input, in seconds.
te_embed_tokenization_durationHistogramTime spent tokenizing one input, in seconds.
te_embed_queue_durationHistogramTime one input waited in the queue, in seconds.
te_embed_inference_durationHistogramTime spent running the model for one input, in seconds.

Unlike the request metrics, the embedding metrics are recorded per input: a request with 8 inputs increments te_request_count by 1 and te_embed_count by 8.

Prediction metrics

These metrics are recorded by the classification and reranking routes: /predict and /rerank, as well as their gRPC equivalents.

MetricTypeDescription
te_predict_countCounterNumber of inputs sent for prediction.
te_predict_successCounterNumber of inputs predicted successfully.
te_predict_durationHistogramEnd-to-end time to predict one input, in seconds.
te_predict_tokenization_durationHistogramTime spent tokenizing one input, in seconds.
te_predict_queue_durationHistogramTime one input waited in the queue, in seconds.
te_predict_inference_durationHistogramTime spent running the model for one input, in seconds.

Like the embedding metrics, they are recorded per input. For /rerank, every query-text pair counts as one input.

Queue and batching metrics

MetricTypeDescription
te_queue_sizeGaugeNumber of inputs waiting for dispatch. Inputs remain counted in prefetched batches until handed to the backend, and are removed if the client disconnects.
te_batch_next_sizeHistogramNumber of inputs returned by each scheduler poll, including zero when no batch is available.
te_batch_next_tokensHistogramNumber of tokens, excluding padding, returned by each scheduler poll. Empty polls record zero. Non-empty batches are bounded by --max-batch-tokens.

Histogram buckets

MetricsBuckets
All *_duration histograms35 buckets growing by a factor of 1.5, from 15 µs to about 14.6 s.
te_request_input_lengthPowers of 2, with extra steps in between from 512 to 32768 (768, 1536, 3072, …), capped at the model’s maximum input length.
te_batch_next_sizeEvery integer from 1 to 32, then 64, 128, 256, 512, 1024, 2048 and 4096.
te_batch_next_tokensSame steps as te_request_input_length, up to 1048576.

Example queries

Request rate per method:

sum by (method) (rate(te_request_count[5m]))

Failure rate per reason:

sum by (err) (rate(te_request_failure[5m]))

95th percentile request latency:

histogram_quantile(0.95, sum by (le) (rate(te_request_duration_bucket[5m])))

Tokenized input tokens per second:

rate(te_request_input_length_sum[5m])

Average number of inputs per scheduler poll, including empty polls:

rate(te_batch_next_size_sum[5m]) / rate(te_batch_next_size_count[5m])

See also

  • CLI arguments for --prometheus-port, --max-concurrent-requests, --max-batch-tokens and --max-client-batch-size.
  • Each HTTP response also includes per-request timings in x-*-time headers, in milliseconds.
  • TEI also supports distributed tracing with OpenTelemetry. Set --otlp-endpoint to the address of an OTLP collector to export traces.
Update on GitHub