> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-pt-br/sdks/backend-sdk/selphid/technical_documentation/api_reference/management/api-v1-selphid-metrics.md).

# /api/v1/selphid/metrics

Returns a cheap JSON snapshot of the service, suitable for frequent scraping: it never calls the SDK nor runs a health check. The `traffic`, `saturation`, `latency` and `quality` figures are accumulated in memory since the service started. It is available in every image variant and never requires a JWT.

| Block                        | Content                                                                                                                               |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `schemaVersion`, `timestamp` | Payload version (`1.0`) and UTC instant of the snapshot                                                                               |
| `service`                    | `name` (`facephi-selphid-service`), `version`, `pathBase` (`/api/v1/selphid`), `uptimeSeconds` and `configuredThreads`                |
| `state`                      | `initialized`, `sdk` (result of the last call to `GET /api/v1/selphid/health`) and `classification`                                   |
| `traffic`                    | Every request served, management endpoints included: `totals`, `1m`/`5m`/`15m` windows and `byEndpoint`                               |
| `saturation`                 | `inflight`, `maxInflight1m`, `configuredThreads`, `queueP95Ms1m` and `backlogSuspected`                                               |
| `latency`                    | Total (`totalMs`), queue (`queueMs`) and processing (`sdkMs`) latency in milliseconds (`avg`, `p50`, `p95`, `p99`, `max`) per window  |
| `usage`                      | Requests per business endpoint (`operations`, keyed by `<METHOD> <path>`) and their `total`. The management endpoints are not counted |
| `quality`                    | Aggregated quality of the extraction, facial authentication and passive liveness results                                              |
| `alerts`                     | Active alerts                                                                                                                         |

When `metrics_enabled` is `false` no request is recorded: `traffic`, `latency`, `usage` and the in-flight and queue figures of `saturation` stay at zero. `errorRate` counts every `4xx` and `5xx` response, `401` included.

A sample is of low quality only when the SDK could not evaluate it: an invalid extraction, a `Bad` `facialQuality`, a `faceConfidence` below `0.5`, a `None`, `NoneBecause*` or `Invalid*` status or diagnostic, or an `Error` or `Invalid` `fPadStatus`/`fMadStatus`. Business verdicts such as a `Negative` or `Uncertain` authentication, a `Spoof` or `NoLive` diagnostic, a `Failed` PAD/MAD status or `NoneBecauseTokenSecurity` (a token reused in another session) are counted in `quality` but never raise the `LOW_QUALITY` alert nor degrade the classification.

Alerts:

| `code`            | `severity` | `message`                                              | Active when                                                                        |
| ----------------- | ---------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------- |
| `SDK_UNAVAILABLE` | `critical` | `SDK health check failed`                              | The SDK is not initialized, or the last call to `/health` failed                   |
| `HIGH_ERROR_RATE` | `warning`  | `5m error rate is above the warning threshold`         | The 5-minute error rate reaches `metrics_error_rate_warning`                       |
| `SATURATED`       | `warning`  | `Queue latency and inflight indicate saturation`       | `state.classification` is `saturated`                                              |
| `LOW_QUALITY`     | `warning`  | `Recent SelphID quality signals show degraded results` | The last low-quality sample happened within `metrics_quality_alert_window_seconds` |
| `IDLE`            | `info`     | `Traffic is below the idle threshold`                  | `state.classification` is `idle`                                                   |

The classification thresholds (`metrics_*`) are configured at startup in `config.json` or with the `FACEPHI_SELPHID_REST_METRICS_*` environment variables.

```json
{"openapi":"3.0.0","info":{"title":"SelphID-SDK Rest API","version":"6.22.0"},"security":[],"paths":{"/api/v1/selphid/metrics":{"get":{"description":"Returns a cheap JSON snapshot of the service, suitable for frequent scraping: it never calls the SDK nor runs\na health check. The `traffic`, `saturation`, `latency` and `quality` figures are accumulated in memory since\nthe service started. It is available in every image variant and never requires a JWT.\n\n| Block | Content |\n|---|---|\n| `schemaVersion`, `timestamp` | Payload version (`1.0`) and UTC instant of the snapshot |\n| `service` | `name` (`facephi-selphid-service`), `version`, `pathBase` (`/api/v1/selphid`), `uptimeSeconds` and `configuredThreads` |\n| `state` | `initialized`, `sdk` (result of the last call to `GET /api/v1/selphid/health`) and `classification` |\n| `traffic` | Every request served, management endpoints included: `totals`, `1m`/`5m`/`15m` windows and `byEndpoint` |\n| `saturation` | `inflight`, `maxInflight1m`, `configuredThreads`, `queueP95Ms1m` and `backlogSuspected` |\n| `latency` | Total (`totalMs`), queue (`queueMs`) and processing (`sdkMs`) latency in milliseconds (`avg`, `p50`, `p95`, `p99`, `max`) per window |\n| `usage` | Requests per business endpoint (`operations`, keyed by `<METHOD> <path>`) and their `total`. The management endpoints are not counted |\n| `quality` | Aggregated quality of the extraction, facial authentication and passive liveness results |\n| `alerts` | Active alerts |\n\nWhen `metrics_enabled` is `false` no request is recorded: `traffic`, `latency`, `usage` and the in-flight and\nqueue figures of `saturation` stay at zero. `errorRate` counts every `4xx` and `5xx` response, `401` included.\n\nA sample is of low quality only when the SDK could not evaluate it: an invalid extraction, a `Bad`\n`facialQuality`, a `faceConfidence` below `0.5`, a `None`, `NoneBecause*` or `Invalid*` status or diagnostic,\nor an `Error` or `Invalid` `fPadStatus`/`fMadStatus`. Business verdicts such as a `Negative` or `Uncertain`\nauthentication, a `Spoof` or `NoLive` diagnostic, a `Failed` PAD/MAD status or `NoneBecauseTokenSecurity` (a\ntoken reused in another session) are counted in `quality` but never raise the `LOW_QUALITY` alert nor degrade\nthe classification.\n\nAlerts:\n\n| `code` | `severity` | `message` | Active when |\n|---|---|---|---|\n| `SDK_UNAVAILABLE` | `critical` | `SDK health check failed` | The SDK is not initialized, or the last call to `/health` failed |\n| `HIGH_ERROR_RATE` | `warning` | `5m error rate is above the warning threshold` | The 5-minute error rate reaches `metrics_error_rate_warning` |\n| `SATURATED` | `warning` | `Queue latency and inflight indicate saturation` | `state.classification` is `saturated` |\n| `LOW_QUALITY` | `warning` | `Recent SelphID quality signals show degraded results` | The last low-quality sample happened within `metrics_quality_alert_window_seconds` |\n| `IDLE` | `info` | `Traffic is below the idle threshold` | `state.classification` is `idle` |\n\nThe classification thresholds (`metrics_*`) are configured at startup in `config.json` or with the\n`FACEPHI_SELPHID_REST_METRICS_*` environment variables.\n","tags":["Management"],"responses":{"200":{"description":"Operational metrics snapshot.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MetricsSnapshot"}}}}}}}},"components":{"schemas":{"MetricsSnapshot":{"type":"object","description":"Operational metrics snapshot. The `traffic`, `saturation`, `latency` and `quality` figures are accumulated in\nmemory since the service started. Key order is not part of the contract; ignore unknown fields.\n","properties":{"schemaVersion":{"type":"string","description":"Version of the payload format."},"timestamp":{"type":"string","description":"UTC instant of the snapshot, with second precision."},"service":{"type":"object","description":"Identity of the service.","properties":{"name":{"type":"string"},"version":{"type":"string"},"pathBase":{"type":"string"},"uptimeSeconds":{"type":"integer"},"configuredThreads":{"type":"integer"}}},"state":{"$ref":"#/components/schemas/MetricsState"},"traffic":{"$ref":"#/components/schemas/MetricsTraffic"},"saturation":{"$ref":"#/components/schemas/MetricsSaturation"},"latency":{"$ref":"#/components/schemas/MetricsLatency"},"usage":{"$ref":"#/components/schemas/MetricsUsage"},"quality":{"$ref":"#/components/schemas/MetricsQuality"},"alerts":{"type":"array","description":"Active alerts. Empty when no condition is raised.","items":{"$ref":"#/components/schemas/MetricsAlert"}}}},"MetricsState":{"type":"object","description":"Start up state, cached SDK health and classification of the service.","properties":{"initialized":{"type":"boolean","description":"Whether the SDK was loaded successfully when the service started."},"classification":{"type":"string","description":"Summary of the snapshot. The cases are evaluated in the listed order and the first one that applies wins.","enum":["unhealthy","unknown","saturated","degraded","idle","ok"]},"sdk":{"type":"object","description":"Result of the last call to `GET /api/v1/selphid/health`. Reading the metrics never runs a health check.","properties":{"alive":{"type":"boolean","description":"Result of the last health check. `false` until the first one."},"healthy":{"type":"boolean","description":"Same value as `alive`."},"initialized":{"type":"boolean"},"lastHealthKnown":{"type":"boolean","description":"`false` until `GET /api/v1/selphid/health` is called for the first time."},"lastHealthCheckAt":{"type":"string","description":"UTC instant of the last health check, empty until the first one."},"lastError":{"type":"string","description":"Detail of the last failed health check, empty when it succeeded."}}}}},"MetricsTraffic":{"type":"object","description":"Every request served, management endpoints included.","properties":{"totals":{"$ref":"#/components/schemas/MetricsTrafficCounters"},"windows":{"type":"object","description":"Sliding windows of 1, 5 and 15 minutes.","properties":{"1m":{"$ref":"#/components/schemas/MetricsTrafficWindow"},"5m":{"$ref":"#/components/schemas/MetricsTrafficWindow"},"15m":{"$ref":"#/components/schemas/MetricsTrafficWindow"}}},"byEndpoint":{"type":"array","description":"One entry per endpoint that has already received requests.","items":{"allOf":[{"type":"object","properties":{"method":{"type":"string"},"path":{"type":"string"}}},{"$ref":"#/components/schemas/MetricsTrafficCounters"}]}}}},"MetricsTrafficCounters":{"type":"object","properties":{"requests":{"type":"integer"},"success":{"type":"integer"},"clientErrors":{"type":"integer"},"serverErrors":{"type":"integer"},"unauthorized":{"type":"integer"}}},"MetricsTrafficWindow":{"type":"object","properties":{"requests":{"type":"integer"},"rps":{"type":"number"},"successRate":{"type":"number"},"errorRate":{"type":"number","description":"Share of `4xx` and `5xx` responses in the window."},"clientErrors":{"type":"integer"},"serverErrors":{"type":"integer"},"unauthorized":{"type":"integer"}}},"MetricsSaturation":{"type":"object","properties":{"inflight":{"type":"integer","description":"Requests in flight, the one reading the metrics included."},"maxInflight1m":{"type":"integer"},"configuredThreads":{"type":"integer"},"queueP95Ms1m":{"type":"integer","description":"95th percentile of the queue latency in the last minute, in milliseconds."},"backlogSuspected":{"type":"boolean"}}},"MetricsLatency":{"type":"object","properties":{"scope":{"type":"string"},"windows":{"type":"object","properties":{"1m":{"$ref":"#/components/schemas/MetricsLatencyWindow"},"5m":{"$ref":"#/components/schemas/MetricsLatencyWindow"},"15m":{"$ref":"#/components/schemas/MetricsLatencyWindow"}}}}},"MetricsLatencyWindow":{"type":"object","properties":{"totalMs":{"$ref":"#/components/schemas/MetricsLatencyStats"},"queueMs":{"$ref":"#/components/schemas/MetricsLatencyStats"},"sdkMs":{"$ref":"#/components/schemas/MetricsLatencyStats"}}},"MetricsLatencyStats":{"type":"object","description":"Latency in milliseconds.","properties":{"avg":{"type":"integer"},"p50":{"type":"integer"},"p95":{"type":"integer"},"p99":{"type":"integer"},"max":{"type":"integer"}}},"MetricsUsage":{"type":"object","description":"Requests served per business endpoint since the service started. The management endpoints (`health`, `version`, `config` and `metrics`) are not counted.","properties":{"enabled":{"type":"boolean","description":"Always `true`."},"operations":{"type":"object","description":"Requests per operation, keyed by `<METHOD> <path>`.","additionalProperties":{"type":"integer"}},"total":{"type":"integer","description":"Sum of `operations`."}}},"MetricsQuality":{"type":"object","description":"Aggregated quality of the results returned by the service since it started. Empty until the first sample;\neach block appears with its first sample and `summary` appears as soon as any other block does.\n","properties":{"facialAuthentication":{"type":"object","description":"Results of `/authenticate-facial/images`, `/authenticate-facial/image/template`, `/authenticate-facial/templates`, `/authenticate-facial/document/face-image` and `/authenticate-facial/document/face-template`.","properties":{"samples":{"type":"integer"},"positive":{"type":"integer","description":"Results whose `authStatus` is `Positive`."},"negative":{"type":"integer","description":"Results with any other `authStatus`."},"similarity":{"$ref":"#/components/schemas/MetricsNumericSummary"}}},"extraction":{"type":"object","description":"Results of `/extract` and `/extract/template`.","properties":{"okCount":{"type":"integer"},"errorCount":{"type":"integer"},"faceConfidence":{"$ref":"#/components/schemas/MetricsNumericSummary"},"facialQualityCounts":{"$ref":"#/components/schemas/MetricsCounters"}}},"liveness":{"type":"object","description":"Results of `/passive-liveness/evaluate` and `/passive-liveness/evaluate/token`.","properties":{"diagnosticCounts":{"$ref":"#/components/schemas/MetricsCounters"},"noLiveDetails":{"type":"object","properties":{"fPadStatusCounts":{"$ref":"#/components/schemas/MetricsCounters"},"fMadStatusCounts":{"$ref":"#/components/schemas/MetricsCounters"},"fPadScore":{"$ref":"#/components/schemas/MetricsNumericSummary"},"fMadScore":{"$ref":"#/components/schemas/MetricsNumericSummary"},"coercionScore":{"$ref":"#/components/schemas/MetricsNumericSummary"}}}}},"tracking":{"type":"object","description":"Api Tracking results of the authentication and liveness operations.","properties":{"statusCounts":{"$ref":"#/components/schemas/MetricsCounters"}}},"summary":{"type":"object","properties":{"lowQualitySamples":{"type":"integer","description":"Samples the SDK could not evaluate, accumulated since the service started."},"lowQualitySince":{"type":"string","description":"UTC instant of the first low-quality sample since the service started. Only present when there is one."}}}}},"MetricsNumericSummary":{"type":"object","description":"Summary of an observed figure. Only present once at least one sample was observed.","properties":{"samples":{"type":"integer"},"avg":{"type":"number"},"min":{"type":"number"},"max":{"type":"number"}}},"MetricsCounters":{"type":"object","description":"Number of results per value, keyed by the value returned by the SDK.","additionalProperties":{"type":"integer"}},"MetricsAlert":{"type":"object","properties":{"code":{"type":"string","enum":["SDK_UNAVAILABLE","HIGH_ERROR_RATE","SATURATED","LOW_QUALITY","IDLE"]},"severity":{"type":"string","enum":["critical","warning","info"]},"message":{"type":"string"},"since":{"type":"string","description":"UTC instant with second precision. For `SDK_UNAVAILABLE`, the instant of the failed health check; for\n`LOW_QUALITY`, the first low-quality sample of the alert currently raised; for the other alerts, the\ninstant of the snapshot.\n"}}}}}}
```
