aiRequestMs function

int aiRequestMs(
  1. Map<String, String> headers,
  2. int localMs
)

The request duration to record for a provider call: the Hub-reported upstream time from kAiProxyElapsedMsHeader when present (proxied requests), otherwise the locally measured localMs.

Implementation

int aiRequestMs(Map<String, String> headers, int localMs) {
  final raw = headers[kAiProxyElapsedMsHeader];
  final reported = raw == null ? null : int.tryParse(raw.trim());
  return (reported != null && reported >= 0) ? reported : localMs;
}