# Query AI latency, traces, logs, and unit economics

URL: https://docs.hanzo.ai/docs/guides/infrastructure/o11y-traces-and-metrics

> Query live GenAI latency percentiles, token spend, traces, logs, and alerts across /v1/eval/metrics, /v1/metrics/query, and /v1/o11y/alerts.

**You cannot optimize latency or unit economics in the dark.** Hanzo tags every model, tool, and HTTP span by org and project so observability and billing share one source of truth.

## Architecture & contract

`/v1/eval/metrics` summarizes GenAI spans (generations, tokens, cents, error rate, p50/p95 latency); `/v1/metrics/*` serves raw PromQL, log, and trace queries; `/v1/o11y/alerts` manages operational alerting.

**Primary endpoint:** `GET /v1/eval/metrics` · \*_Status:_\* `shipped` · \*_Level:_\* `practitioner`

## Run it across all four surfaces

**CLI**

```bash
hanzo eval metrics
hanzo metrics health
hanzo o11y alerts list
```

**SDK**

**TypeScript**

```ts
import { Configuration, EvalApi, MetricsApi } from 'hanzoai';

const cfg = new Configuration({ accessToken: process.env.HANZO_API_KEY });
const [aiMetrics, health] = await Promise.all([
  new EvalApi(cfg).getEvalMetrics('24h'),
  new MetricsApi(cfg).getMetricsHealth(),
]);
console.log({ aiMetrics: aiMetrics.data, health: health.data });
```

**Python**

```python
import os
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import EvalApi, MetricsApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
print(EvalApi(client).get_eval_metrics(range="24h"))
print(MetricsApi(client).get_metrics_health())
```

**HTTP**

```bash
curl -s "https://api.hanzo.ai/v1/eval/metrics?range=24h" \
  -H "Authorization: Bearer $HANZO_API_KEY" | jq '.'

curl -s https://api.hanzo.ai/v1/metrics/health \
  -H "Authorization: Bearer $HANZO_API_KEY" | jq '.'

curl -s https://api.hanzo.ai/v1/o11y/alerts \
  -H "Authorization: Bearer $HANZO_API_KEY" | jq '.'
```

**MCP**

```bash
curl -s -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "eval",
      "arguments": {"op": "get_eval_metrics", "input": {"range": "24h"}}
    }
  }'
```

## Verify the outcome

- Assert `GET /v1/eval/metrics?range=24h` reflects recent model calls with accurate per-model latency breakdowns.

## Production guardrails

- Alert on `error_rate > 1%` and `p95_latency_ms` regressions rather than average latency alone.

## Next steps & Hanzo University

- [Drift Detection & History](https://docs.hanzo.ai/docs/guides/science/drift-detection-history)

- **[ARC 105 — AI Architect](https://hanzo.university/ai-architect)** ([Launch interactive lab on hanzo.app/learn](https://hanzo.app/learn/ai-architect))

- **[SYS 103 — Systems Engineering](https://hanzo.university/systems-engineering)** ([Launch interactive lab on hanzo.app/learn](https://hanzo.app/learn/systems-engineering))
