The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(cookbook): add a Grafana dashboard for the OTel GenAI metrics (#35159)
Yassin Kortam59118ae5b648
diff --git a/cookbook/litellm_proxy_server/grafana_dashboard/dashboard_genai_otel/grafana_dashboard.json b/cookbook/litellm_proxy_server/grafana_dashboard/dashboard_genai_otel/grafana_dashboard.jsonnew file mode 100644index 00000000000..70608a2ffe8--- /dev/null+++ b/cookbook/litellm_proxy_server/grafana_dashboard/dashboard_genai_otel/grafana_dashboard.json@@ -0,0 +1,523 @@+{+ "annotations": {+ "list": []+ },+ "editable": true,+ "fiscalYearStartMonth": 0,+ "graphTooltip": 0,+ "links": [],+ "panels": [+ {+ "type": "stat",+ "title": "Requests",+ "gridPos": {+ "h": 4,+ "w": 6,+ "x": 0,+ "y": 0+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "short",+ "decimals": 0,+ "color": {+ "mode": "fixed",+ "fixedColor": "blue"+ }+ },+ "overrides": []+ },+ "options": {+ "reduceOptions": {+ "calcs": [+ "lastNotNull"+ ],+ "fields": "",+ "values": false+ },+ "colorMode": "background",+ "graphMode": "none"+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "instant": true,+ "expr": "sum(increase(gen_ai_client_operation_duration_seconds_count{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__range]))"+ }+ ],+ "id": 1+ },+ {+ "type": "stat",+ "title": "Spend",+ "description": "LiteLLM's computed cost for the selected window, from gen_ai.usage.cost",+ "gridPos": {+ "h": 4,+ "w": 6,+ "x": 6,+ "y": 0+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "currencyUSD",+ "decimals": 4,+ "color": {+ "mode": "fixed",+ "fixedColor": "green"+ }+ },+ "overrides": []+ },+ "options": {+ "reduceOptions": {+ "calcs": [+ "lastNotNull"+ ],+ "fields": "",+ "values": false+ },+ "colorMode": "background",+ "graphMode": "none"+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "instant": true,+ "expr": "sum(increase(gen_ai_usage_cost_USD_sum{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__range]))"+ }+ ],+ "id": 2+ },+ {+ "type": "stat",+ "title": "Tokens",+ "gridPos": {+ "h": 4,+ "w": 6,+ "x": 12,+ "y": 0+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "short",+ "decimals": 0,+ "color": {+ "mode": "fixed",+ "fixedColor": "purple"+ }+ },+ "overrides": []+ },+ "options": {+ "reduceOptions": {+ "calcs": [+ "lastNotNull"+ ],+ "fields": "",+ "values": false+ },+ "colorMode": "background",+ "graphMode": "none"+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "instant": true,+ "expr": "sum(increase(gen_ai_client_token_usage_sum{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__range]))"+ }+ ],+ "id": 3+ },+ {+ "type": "stat",+ "title": "p95 request duration",+ "gridPos": {+ "h": 4,+ "w": 6,+ "x": 18,+ "y": 0+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "s",+ "decimals": 2,+ "color": {+ "mode": "fixed",+ "fixedColor": "orange"+ }+ },+ "overrides": []+ },+ "options": {+ "reduceOptions": {+ "calcs": [+ "lastNotNull"+ ],+ "fields": "",+ "values": false+ },+ "colorMode": "background",+ "graphMode": "none"+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "instant": true,+ "expr": "histogram_quantile(0.95, sum by (le) (rate(gen_ai_client_operation_duration_seconds_bucket{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__range])))"+ }+ ],+ "id": 4+ },+ {+ "type": "timeseries",+ "title": "Request rate by model",+ "gridPos": {+ "h": 8,+ "w": 12,+ "x": 0,+ "y": 4+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "reqpm",+ "custom": {+ "lineWidth": 2,+ "fillOpacity": 8,+ "showPoints": "never"+ }+ },+ "overrides": []+ },+ "options": {+ "legend": {+ "displayMode": "list",+ "placement": "bottom"+ },+ "tooltip": {+ "mode": "multi",+ "sort": "desc"+ }+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "legendFormat": "{{gen_ai_request_model}}",+ "expr": "sum by (gen_ai_request_model) (rate(gen_ai_client_operation_duration_seconds_count{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__rate_interval])) * 60"+ }+ ],+ "id": 5+ },+ {+ "type": "timeseries",+ "title": "Spend rate by model",+ "description": "USD per hour, derived from the gen_ai.usage.cost histogram",+ "gridPos": {+ "h": 8,+ "w": 12,+ "x": 12,+ "y": 4+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "currencyUSD",+ "custom": {+ "lineWidth": 2,+ "fillOpacity": 8,+ "showPoints": "never"+ }+ },+ "overrides": []+ },+ "options": {+ "legend": {+ "displayMode": "list",+ "placement": "bottom"+ },+ "tooltip": {+ "mode": "multi",+ "sort": "desc"+ }+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "legendFormat": "{{gen_ai_request_model}}",+ "expr": "sum by (gen_ai_request_model) (rate(gen_ai_usage_cost_USD_sum{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__rate_interval])) * 3600"+ }+ ],+ "id": 6+ },+ {+ "type": "timeseries",+ "title": "Tokens per minute by model and type",+ "description": "gen_ai.client.token.usage split by the gen_ai.token.type attribute",+ "gridPos": {+ "h": 8,+ "w": 12,+ "x": 0,+ "y": 12+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "short",+ "custom": {+ "lineWidth": 2,+ "fillOpacity": 8,+ "showPoints": "never"+ }+ },+ "overrides": []+ },+ "options": {+ "legend": {+ "displayMode": "list",+ "placement": "bottom"+ },+ "tooltip": {+ "mode": "multi",+ "sort": "desc"+ }+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "legendFormat": "{{gen_ai_request_model}} {{gen_ai_token_type}}",+ "expr": "sum by (gen_ai_request_model, gen_ai_token_type) (rate(gen_ai_client_token_usage_sum{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__rate_interval])) * 60"+ }+ ],+ "id": 7+ },+ {+ "type": "timeseries",+ "title": "p95 request duration by model",+ "gridPos": {+ "h": 8,+ "w": 12,+ "x": 12,+ "y": 12+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "s",+ "custom": {+ "lineWidth": 2,+ "fillOpacity": 0,+ "showPoints": "never"+ }+ },+ "overrides": []+ },+ "options": {+ "legend": {+ "displayMode": "list",+ "placement": "bottom"+ },+ "tooltip": {+ "mode": "multi",+ "sort": "desc"+ }+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "legendFormat": "{{gen_ai_request_model}}",+ "expr": "histogram_quantile(0.95, sum by (le, gen_ai_request_model) (rate(gen_ai_client_operation_duration_seconds_bucket{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__rate_interval])))"+ }+ ],+ "id": 8+ },+ {+ "type": "timeseries",+ "title": "p95 time to first token (streaming)",+ "description": "gen_ai.server.time_to_first_token, recorded only for streaming requests",+ "gridPos": {+ "h": 8,+ "w": 12,+ "x": 0,+ "y": 20+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "s",+ "custom": {+ "lineWidth": 2,+ "fillOpacity": 0,+ "showPoints": "never"+ }+ },+ "overrides": []+ },+ "options": {+ "legend": {+ "displayMode": "list",+ "placement": "bottom"+ },+ "tooltip": {+ "mode": "multi",+ "sort": "desc"+ }+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "legendFormat": "{{gen_ai_request_model}}",+ "expr": "histogram_quantile(0.95, sum by (le, gen_ai_request_model) (rate(gen_ai_server_time_to_first_token_seconds_bucket{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__rate_interval])))"+ }+ ],+ "id": 9+ },+ {+ "type": "timeseries",+ "title": "p95 provider generation time",+ "description": "gen_ai.client.response.duration, upstream generation time excluding LiteLLM overhead",+ "gridPos": {+ "h": 8,+ "w": 12,+ "x": 12,+ "y": 20+ },+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "fieldConfig": {+ "defaults": {+ "unit": "s",+ "custom": {+ "lineWidth": 2,+ "fillOpacity": 0,+ "showPoints": "never"+ }+ },+ "overrides": []+ },+ "options": {+ "legend": {+ "displayMode": "list",+ "placement": "bottom"+ },+ "tooltip": {+ "mode": "multi",+ "sort": "desc"+ }+ },+ "targets": [+ {+ "refId": "A",+ "editorMode": "code",+ "legendFormat": "{{gen_ai_request_model}}",+ "expr": "histogram_quantile(0.95, sum by (le, gen_ai_request_model) (rate(gen_ai_client_response_duration_seconds_bucket{service_name=~\"$service\", gen_ai_request_model=~\"$model\"}[$__rate_interval])))"+ }+ ],+ "id": 10+ }+ ],+ "preload": false,+ "refresh": "30s",+ "schemaVersion": 42,+ "tags": [+ "litellm",+ "genai",+ "opentelemetry"+ ],+ "templating": {+ "list": [+ {+ "name": "datasource",+ "label": "Prometheus",+ "type": "datasource",+ "query": "prometheus",+ "current": {},+ "hide": 0+ },+ {+ "name": "service",+ "label": "Service",+ "type": "query",+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "query": "label_values(gen_ai_client_operation_duration_seconds_count, service_name)",+ "refresh": 2,+ "includeAll": true,+ "multi": true,+ "current": {+ "text": "All",+ "value": "$__all"+ }+ },+ {+ "name": "model",+ "label": "Model",+ "type": "query",+ "datasource": {+ "type": "prometheus",+ "uid": "${datasource}"+ },+ "query": "label_values(gen_ai_client_operation_duration_seconds_count{service_name=~\"$service\"}, gen_ai_request_model)",+ "refresh": 2,+ "includeAll": true,+ "multi": true,+ "current": {+ "text": "All",+ "value": "$__all"+ }+ }+ ]+ },+ "time": {+ "from": "now-1h",+ "to": "now"+ },+ "timepicker": {},+ "timezone": "browser",+ "title": "LiteLLM GenAI (OpenTelemetry)",+ "uid": "litellm-genai-otel",+ "weekStart": ""+}diff --git a/cookbook/litellm_proxy_server/grafana_dashboard/dashboard_genai_otel/readme.md b/cookbook/litellm_proxy_server/grafana_dashboard/dashboard_genai_otel/readme.mdnew file mode 100644index 00000000000..c51f0166462--- /dev/null+++ b/cookbook/litellm_proxy_server/grafana_dashboard/dashboard_genai_otel/readme.md@@ -0,0 +1,35 @@+# LiteLLM GenAI dashboard (OpenTelemetry metrics)++Dashboard for the `gen_ai.*` metrics the OpenTelemetry v2 integration emits, as opposed to the `litellm_*` Prometheus metrics the other dashboards in this folder chart.++Import `grafana_dashboard.json` from **Dashboards > New > Import** and pick your Prometheus data source. Panels: request count, spend, token count, p95 duration, request rate by model, spend rate per hour by model, tokens per minute split by input and output, p95 duration by model, p95 time to first token, and p95 provider generation time. Template variables for data source, service, and model.++## Pre-requisites++Metrics are off by default. In the proxy environment:++```shell+LITELLM_OTEL_V2=true+LITELLM_OTEL_INTEGRATION_ENABLE_METRICS=true+OTEL_EXPORTER="otlp_http"+OTEL_ENDPOINT="<your OTLP endpoint>"+```++You also need the metric attribute filter, or the panels will plot flat lines at zero. LiteLLM's default attribute set includes per-request fields, so nearly every request lands in its own time series with a single sample, and `rate()` has nothing to compute over:++```yaml title="config.yaml"+callback_settings:+ otel:+ attributes:+ include_list:+ - gen_ai.operation.name+ - gen_ai.system+ - gen_ai.request.model+ - gen_ai.framework+```++See [Grafana Cloud](https://docs.litellm.ai/docs/observability/grafana_cloud) for the full setup, and [OpenTelemetry v2](https://docs.litellm.ai/docs/observability/opentelemetry_v2#metrics) for the metric reference.++## Note on Grafana's AI Observability integration++Grafana Cloud ships prebuilt GenAI dashboards that query these same metric names, so they look like a drop-in alternative to this one. They are not: twenty of their twenty-two panels filter on `telemetry_sdk_name="openlit"`, a label LiteLLM does not carry and cannot be configured to add, so those panels stay empty.diff --git a/cookbook/litellm_proxy_server/grafana_dashboard/readme.md b/cookbook/litellm_proxy_server/grafana_dashboard/readme.mdindex 81235c308f2..a1564a406e0 100644--- a/cookbook/litellm_proxy_server/grafana_dashboard/readme.md+++ b/cookbook/litellm_proxy_server/grafana_dashboard/readme.md@@ -2,6 +2,10 @@This folder contains the `json` for creating Grafana Dashboards+## [LiteLLM GenAI Dashboard (OpenTelemetry)](./dashboard_genai_otel)++Charts the `gen_ai.*` metrics from the OpenTelemetry v2 integration: spend, tokens, request rate, and latency percentiles by model. Separate from the dashboards below, which chart the `litellm_*` Prometheus metrics.+## [LiteLLM v2 Dashboard](./dashboard_v2)<img width="1316" alt="grafana_1" src="https://github.com/user-attachments/assets/d0df802d-0cb9-4906-a679-941c547789ab">