Defend

Health and readiness

Liveness, readiness, and Prometheus metrics endpoints for operating Defend in production.

GET /v1/health

Liveness-style check. Returns JSON including registered providers and whether each supports modules.

Prop

Type

Health check
curl -s http://localhost:8000/v1/health
httpx client
import httpx

r = httpx.get("http://localhost:8000/v1/health")
print(r.json())

GET /v1/ready

Readiness check that warms session state and, only when provider is defend, loads the local Hugging Face classifier. Returns 200 with {"status":"ready"} when healthy.

If you use defend as the provider without pydefend[local] (or without the adxzer/defend:local image), the defend subsystem fails readiness with an import or load error.

When initialization fails, returns 503 with JSON describing which subsystem failed (defend, session_accumulator, etc.).

Readiness check
curl -s -i http://localhost:8000/v1/ready

Expect 200 with {"status":"ready"} when healthy, or 503 when a subsystem is still initializing.

httpx client
import httpx

r = httpx.get("http://localhost:8000/v1/ready")
print(r.status_code, r.text)

Load balancers

Point Kubernetes HTTP readiness probes (or equivalents) at /v1/ready so traffic only hits instances that finished model warm-up.

GET /v1/metrics

Prometheus metrics exposed via prometheus-fastapi-instrumentator. This route is not included in the OpenAPI schema but is stable for scraping.

Metrics
curl -s http://localhost:8000/v1/metrics
httpx client
import httpx

r = httpx.get("http://localhost:8000/v1/metrics")
print(r.text[:500])

See Production for suggested alerting dimensions.