An SLO (Service Level Objective) is a formal quality target with a measurement method and an alert when you breach it. For AI systems, SLOs extend beyond uptime and latency to cover quality metrics that traditional infrastructure doesn't have.
from collections import deque
import time
class AvailabilityTracker:
def __init__(self, window_seconds: int = 300, target: float = 0.995):
self.window = window_seconds
self.target = target
self._events: deque[tuple[float, bool]] = deque()
def record(self, success: bool):
now = time.monotonic()
self._events.append((now, success))
cutoff = now - self.window
while self._events and self._events[0][0] < cutoff:
self._events.popleft()
def current_rate(self) -> float:
if not self._events:
return 1.0
return sum(1 for _, ok in self._events if ok) / len(self._events)
def is_breached(self) -> bool:
return self.current_rate() < self.target
tracker = AvailabilityTracker(window_seconds=300, target=0.995)
try:
response = llm_call(prompt)
tracker.record(success=True)
except Exception:
tracker.record(success=False)
if tracker.is_breached():
send_alert(f"Availability SLO breach: {tracker.current_rate():.1%}")# 99.5% availability SLO → 0.5% error budget = 43.8 hours of downtime/year
def compute_error_budget(target_availability: float, window_days: int = 30) -> dict:
error_budget_pct = 1 - target_availability
total_minutes = window_days * 24 * 60
return {
"error_budget_minutes": total_minutes * error_budget_pct,
"error_budget_hours": total_minutes * error_budget_pct / 60,
}
# Alert when burn rate is 10x the normal rate
def should_alert_on_burn_rate(
consumed_pct: float, # How much error budget consumed
time_elapsed_pct: float, # What fraction of window elapsed
multiplier: float = 10,
) -> bool:
burn_rate = consumed_pct / time_elapsed_pct if time_elapsed_pct > 0 else 0
return burn_rate > multiplierWhat makes a user say "this AI is broken"? Slow responses? Wrong answers? Format errors? Those are your SLI candidates.
Run your metric for 2 weeks to understand the baseline. A target of 99% sounds good until you discover your current rate is 85%.
Start at current performance + 5%. Stretch goals nobody hits are ignored. Achievable targets get tracked.
p95 < 5s is a user-facing SLO. Cache hit rate > 30% is an internal efficiency SLO. Don't put both in your customer-facing SLA.
Quality SLOs need sampling strategies.You can't score 100% of production traffic with an LLM judge — it doubles your API costs. Use a 5–10% sample rate, but ensure the sample is stratified: sample across all operation types and tenants, not just the highest-volume traffic.