import { useEffect, useState } from "react"; import { Area, AreaChart, Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts"; import { Coins, Gauge, MessageSquare, Zap } from "lucide-react"; import { api } from "../lib/api.js"; const tooltipStyle = { background: "#131827", border: "1px solid #232b41", borderRadius: 10, fontSize: 13, color: "#e7eaf3", }; export default function AnalyticsView() { const [data, setData] = useState(null); const [error, setError] = useState(""); useEffect(() => { api("/api/analytics/overview") .then(setData) .catch((err) => setError(err.message)); }, []); if (error) { return (
{error}
); } if (!data) { return (
); } const totalTokens = data.input_tokens + data.output_tokens; const maxTool = Math.max(1, ...data.tools.map((t) => t.count)); return (

Usage analytics

Token consumption, spend and agent activity for your account (last 30 days shown in charts).

Total spend
${data.cost_usd.toFixed(4)}
estimated from provider pricing
Tokens
{totalTokens.toLocaleString()}
{data.input_tokens.toLocaleString()} in / {data.output_tokens.toLocaleString()} out
Messages
{data.total_messages.toLocaleString()}
across {data.total_sessions} session{data.total_sessions === 1 ? "" : "s"}
Avg response
{(data.avg_latency_ms / 1000).toFixed(1)}s
end-to-end, tools included

Daily spend (USD)

d.slice(5)} interval="preserveStartEnd" />

Messages per day

d.slice(5)} interval="preserveStartEnd" />

Cost by model

{data.models.length === 0 ? (
No model usage yet.
) : ( )}

Agent tool activity

{data.tools.length === 0 ? (
The agent has not used any tools yet. Ask about the weather or the web.
) : ( data.tools.map((tool) => (
{tool.name}
{tool.count}
)) )}
); }