> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Export custom metrics

> Send application-defined metrics from a Baseten deployment to your observability provider.

Custom metrics measure behavior inside your model server, such as cache hits, batch sizes, or validation failures.

Expose these metrics through a Prometheus endpoint that your observability system can scrape, or push them directly to your provider with OpenTelemetry.

## Expose a Prometheus endpoint

If you deploy a [custom server](/development/model/custom-server), add a route that returns your metrics in Prometheus format. For example, a `/metrics` route is available through this Baseten endpoint:

```text URL theme={"system"}
https://model-<model-id>.api.baseten.co/environments/production/sync/metrics
```

Configure your external collector to scrape this URL with a [Baseten API key](/organization/api-keys) that can invoke the model. Send the key in the `Authorization` header with the `Bearer` scheme. A `workspace-export-metrics` key only authorizes the organization metrics endpoint, so don't use it for this route.

Check the route with the Baseten CLI before you configure a collector:

```bash theme={"system"} theme={"system"}
baseten api inference production/sync/metrics \
  --model-id <model-id>
```

The response contains the Prometheus metadata and samples from your server:

```text theme={"system"} theme={"system"}
# HELP custom_model_predictions_total Predictions handled by the model server.
# TYPE custom_model_predictions_total counter
custom_model_predictions_total 1
```

Every scrape sends a request to the deployment. If the deployment has scaled to zero, a scrape triggers a [cold start](/deployment/autoscaling/cold-starts). Regular scrapes can keep a replica active.

See [Sync API endpoints](/inference/calling-your-model#sync-api-endpoints) for route mapping and the [Prometheus configuration reference](https://prometheus.io/docs/prometheus/latest/configuration/configuration/) for scrape options.

## Push metrics with OpenTelemetry

You can also instrument your model server with an OpenTelemetry SDK and push metrics to an OTLP endpoint. The exporter sends each batch to your collector or observability provider.

To configure push-based export:

1. Add the OpenTelemetry metrics SDK and an OTLP exporter for your language.
2. Create counters, histograms, or gauges for the application behavior you want to measure.
3. Configure the exporter with your provider's OTLP endpoint and authentication settings.
4. Store provider credentials as [Baseten secrets](/development/model/secrets), not in your model code or configuration.
5. For a custom server, add the Baseten-provided `BT_MODEL_ID` and `BT_MODEL_DEPLOYMENT_ID` values as resource attributes so you can filter metrics by model and deployment.

For a Python implementation, see the OpenTelemetry guides for [metrics instrumentation](https://opentelemetry.io/docs/languages/python/instrumentation/#metrics) and [OTLP exporters](https://opentelemetry.io/docs/languages/python/exporters/#otlp-dependencies).
