# Prometheus metrics

Text Embeddings Inference (TEI) exports [Prometheus](https://prometheus.io/) 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):

| Server | Default | `--prometheus-port` set to a different port than `--port` |
|--------|---------|-----------------------------------------------------------|
| HTTP   | `GET /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. |
| gRPC   | Served on port `9000`. | Metrics are served on the given port. |

> [!NOTE]
> 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`:

```shell
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:

```shell
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.

```shell
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:

```yaml
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.

| Metric | Type | Labels | Description |
|--------|------|--------|-------------|
| `te_request_count` | Counter | `method` | Number of requests received. |
| `te_request_success` | Counter | `method` | Number of requests that completed successfully. |
| `te_request_failure` | Counter | `err` | Number of failed requests, by failure reason. |
| `te_request_duration` | Histogram | | End-to-end time of a successful request, in seconds. |
| `te_request_tokenization_duration` | Histogram | | Time spent tokenizing a successful request, in seconds. |
| `te_request_queue_duration` | Histogram | | Time a successful request waited in the queue, in seconds. |
| `te_request_inference_duration` | Histogram | | Time spent running the model for a successful request, in seconds. |
| `te_request_input_length` | Histogram | | Number 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:

| `err` | Cause |
|-------|-------|
| `validation` | The request is invalid, for example the inputs are empty or `dimensions` is out of range. |
| `batch_size` | The request contains more inputs than `--max-client-batch-size`. |
| `tokenization` | An input could not be tokenized, including inputs longer than the model's maximum input length when truncation is disabled. |
| `model_type` | The route does not match the model, for example `/embed` on a classification model. |
| `overloaded` | The server is already handling `--max-concurrent-requests` requests. HTTP clients receive a `429` status code. |
| `inference` | The model failed to process the input. |
| `dropped` | The client disconnected while its request was waiting in the queue. |
| `missing_values` | gRPC 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.

| Metric | Type | Description |
|--------|------|-------------|
| `te_embed_count` | Counter | Number of inputs sent for embedding. |
| `te_embed_success` | Counter | Number of inputs embedded successfully. |
| `te_embed_duration` | Histogram | End-to-end time to embed one input, in seconds. |
| `te_embed_tokenization_duration` | Histogram | Time spent tokenizing one input, in seconds. |
| `te_embed_queue_duration` | Histogram | Time one input waited in the queue, in seconds. |
| `te_embed_inference_duration` | Histogram | Time 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.

| Metric | Type | Description |
|--------|------|-------------|
| `te_predict_count` | Counter | Number of inputs sent for prediction. |
| `te_predict_success` | Counter | Number of inputs predicted successfully. |
| `te_predict_duration` | Histogram | End-to-end time to predict one input, in seconds. |
| `te_predict_tokenization_duration` | Histogram | Time spent tokenizing one input, in seconds. |
| `te_predict_queue_duration` | Histogram | Time one input waited in the queue, in seconds. |
| `te_predict_inference_duration` | Histogram | Time 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

| Metric | Type | Description |
|--------|------|-------------|
| `te_queue_size` | Gauge | Number 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_size` | Histogram | Number of inputs returned by each scheduler poll, including zero when no batch is available. |
| `te_batch_next_tokens` | Histogram | Number of tokens, excluding padding, returned by each scheduler poll. Empty polls record zero. Non-empty batches are bounded by `--max-batch-tokens`. |

## Histogram buckets

| Metrics | Buckets |
|---------|---------|
| All `*_duration` histograms | 35 buckets growing by a factor of 1.5, from 15 µs to about 14.6 s. |
| `te_request_input_length` | Powers 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_size` | Every integer from 1 to 32, then 64, 128, 256, 512, 1024, 2048 and 4096. |
| `te_batch_next_tokens` | Same 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](./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.

