{% macro integer(value) %}{{ "{:,}".format((value or 0) | int) }}{% endmacro %}
{% macro money(value) %}{% set number = (value or 0) | float %}{% if number < 1 %}${{ "%.6f" | format(number) }}{% else %}${{ "%.2f" | format(number) }}{% endif %}{% endmacro %}
{% macro percent(value, scale=1) %}{{ "%.1f" | format((value or 0) | float * scale) }}%{% endmacro %}
{% macro optional(value) %}{% if value is none %}n/a{% else %}{{ value }}{% endif %}{% endmacro %}
{% macro cards(items) %}
{% for item in items %}
{{ item[1] }}{{ item[0] }}
{% endfor %}
{% endmacro %}
{% macro group_table(title, label, items) %}
{{ title }}
{{ title }}
| {{ label }} | Requests | Tokens | Cost |
{% for item in items or [] %}
| {{ item.key }} | {{ integer(item.requests) }} | {{ integer(item.total_tokens) }} | {{ money(item.cost_usd) }} |
{% endfor %}
{% endmacro %}
{% macro pset_grid(title, sets) %}
{{ title }}
{% for label, pset in sets %}
{{ label }}
{{ label }}
| stat | value |
{% for stat in ["avg", "p50", "p90", "p95", "p99", "max"] %}
| {{ stat }} | {{ integer(pset[stat]) }} |
{% endfor %}
{% endfor %}
{% endmacro %}
Window: {% if usage.window_hours %}{{ usage.window_hours }}h{% else %}all time{% endif %}, updated {{ local_dt(usage.generated_at) }}
{% if not usage.requests %}
No AI gateway traffic recorded in this window yet.
{% else %}
{% set v = usage.volume %}{% set t = usage.tokens %}{% set l = usage.latency %}{% set e = usage.errors %}{% set c = usage.cost %}{% set b = usage.behavior %}{% set conc = v.concurrency or {} %}{% set rpc = b.requests_per_caller or {} %}
Overview
{{ cards([
("Requests", integer(v.requests)),
("Success", percent(v.success / v.requests if v.requests else 0, 100)),
("Error rate", e.error_rate_pct ~ "%"),
("Requests / hour", integer(v.requests_per_hour)),
("Peak req / min", integer(v.peak_requests_per_minute)),
("Cost (window)", money(c.total_usd)),
("Cost this hour", money(c.this_hour_usd)),
("Cost 24h", money(c.last_24h_usd)),
("Projected / month", money(c.projected_monthly_usd)),
("Tokens total", integer(t.total)),
("Upstream avail.", l.upstream_availability_pct ~ "%"),
("Concurrency peak", integer(conc.peak)),
]) }}
Tokens
{{ cards([
("Prompt total", integer(t.prompt_total)),
("Completion total", integer(t.completion_total)),
("Total", integer(t.total)),
("Cache hit rate", percent(t.cache_hit_rate, 100)),
("Input:output", t.input_output_ratio),
("Cache hit tokens", integer(t.cache_hit_total)),
("Cache miss tokens", integer(t.cache_miss_total)),
("Reasoning tokens", integer(t.reasoning_total)),
("Tokens / hour", integer(t.tokens_per_hour)),
("Context util avg", "n/a" if t.context_utilization_avg is none else percent(t.context_utilization_avg, 100)),
]) }}
{{ pset_grid("Token distribution per request", [("Prompt tokens", t.prompt or {}), ("Completion tokens", t.completion or {}), ("Total tokens", t.total_per_request or {})]) }}
Latency and throughput
{{ cards([
("Upstream availability", l.upstream_availability_pct ~ "%"),
("Gateway overhead share", percent(l.gateway_overhead_share, 100)),
("TTFT", "n/a (non-streaming)"),
("Inter-token", "n/a (non-streaming)"),
]) }}
{{ pset_grid("Latency percentiles (ms)", [("Upstream round-trip", l.upstream_ms or {}), ("Gateway overhead", l.gateway_overhead_ms or {}), ("Queue wait", l.queue_wait_ms or {}), ("Connection establish", l.connect_ms or {}), ("Total", l.total_ms or {}), ("Tokens / second", l.tokens_per_second or {})]) }}
Errors and reliability
{{ cards([
("Total errors", integer(e.total)),
("Error rate", e.error_rate_pct ~ "%"),
("4xx", integer(e.count_4xx)),
("5xx", integer(e.count_5xx)),
("Timeouts", integer(e.timeouts)),
("Retries attempted", integer(e.retries_attempted)),
("Retries succeeded", integer(e.retries_succeeded)),
("Circuit opens", integer(e.circuit_open_events)),
]) }}
Errors by category
| Error category | Count |
{% for name, count in (e.by_category or {}).items() %}
| {{ name }} | {{ integer(count) }} |
{% endfor %}
Cost
{{ cards([
("Total", money(c.total_usd)),
("Input cost", money(c.input_usd)),
("Output cost", money(c.output_usd)),
("Per 1k tokens", money(c.effective_per_1k_tokens_usd)),
("Caching savings", money(c.caching_savings_usd)),
("This hour", money(c.this_hour_usd)),
("Last 24h", money(c.last_24h_usd)),
("Projected / month", money(c.projected_monthly_usd)),
]) }}
Behavior
{{ cards([
("Unique callers", integer(b.unique_callers)),
("Req / caller avg", integer(rpc.avg)),
("Req / caller p95", integer(rpc.p95)),
("Heaviest caller", integer(rpc.max)),
("Avg temperature", optional(b.avg_temperature)),
("Avg top_p", optional(b.avg_top_p)),
("Tool calls", integer(b.tool_call_requests)),
("Streaming", integer(b.streaming_requests)),
("Non-streaming", integer(b.non_streaming_requests)),
]) }}
{{ group_table("By model", "Model", v.by_model) }}
{{ group_table("By endpoint", "Endpoint", v.by_endpoint) }}
{{ group_table("By backend", "Backend", v.by_backend) }}
{{ group_table("By caller", "Caller", v.by_caller) }}
User agents
User agents
| User agent | Requests |
{% for item in b.user_agents or [] %}
| {{ item.key }} | {{ integer(item.requests) }} |
{% endfor %}
Hourly breakdown
Hourly breakdown
| Hour | Requests | OK | Failed | Prompt | Completion | Total | Cost | Avg ms | Callers | New |
{% for h in usage.hourly or [] %}
| {{ local_dt(h.hour ~ ":00:00+00:00") }} |
{{ integer(h.requests) }} | {{ integer(h.success) }} | {{ integer(h.failed) }} |
{{ integer(h.prompt_tokens) }} | {{ integer(h.completion_tokens) }} | {{ integer(h.total_tokens) }} |
{{ money(h.cost_usd) }} | {{ integer(h.avg_latency_ms) }} | {{ integer(h.active_owners) }} | {{ integer(h.new_owners) }} |
{% endfor %}
{% endif %}