Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(costs): the speech area lists every speech model with what it consumed and its API price

rubenluetke10-beepbf2fcae8156b
diff --git a/jarvis/costs/aggregate.py b/jarvis/costs/aggregate.py
index d3ba39e75c..5e4690caf7 100644
--- a/jarvis/costs/aggregate.py
+++ b/jarvis/costs/aggregate.py
@@ -54,6 +54,10 @@ class Bucket:
#: Of ``cost_usd``, how much a monthly seat covered rather than an invoice.
subscription_usd: float = 0.0
last_ts_ms: int = 0
+ #: Speech quantities — characters spoken and audio heard — so a speech
+ #: model's row can say what it consumed when it has no tokens to show.
+ chars: int = 0
+ audio_ms: int = 0
#: Secondary dimension — which providers/models/roles fed this bucket.
members: dict[str, float] = field(default_factory=lambda: defaultdict(float))
@@ -62,6 +66,8 @@ class Bucket:
self.tokens_in += entry.tokens_in
self.tokens_out += entry.tokens_out
self.tokens_cached += entry.tokens_cached
+ self.chars += entry.chars
+ self.audio_ms += entry.audio_ms
self.entries += 1
if entry.is_gap:
self.gap_tokens += entry.tokens_total
@@ -84,6 +90,8 @@ class Bucket:
"entries": self.entries,
"gap_tokens": self.gap_tokens,
"subscription_usd": round(self.subscription_usd, 6),
+ "chars": self.chars,
+ "audio_ms": self.audio_ms,
"last_ts_ms": self.last_ts_ms,
"cost_share": round(self.cost_usd / total_cost, 6) if total_cost > 0 else 0.0,
"token_share": round(tokens / total_tokens, 6) if total_tokens > 0 else 0.0,
diff --git a/jarvis/costs/model.py b/jarvis/costs/model.py
index b34c7b5bbb..0c78b5b150 100644
--- a/jarvis/costs/model.py
+++ b/jarvis/costs/model.py
@@ -147,6 +147,11 @@ class CostEntry:
"""Session / mission id — the thing a user can go look at."""
label: str
"""Short human-readable handle for ``ref_id`` (session title, prompt head)."""
+ #: What a speech row actually bought, in the unit it was billed in. Zero on
+ #: every token-billed row. Kept beside the tokens rather than folded into
+ #: them because a character and a token are different units (BUG-177).
+ chars: int = 0
+ audio_ms: int = 0
@property
def tokens_total(self) -> int:
@@ -176,6 +181,8 @@ class CostEntry:
"price_source": self.price_source,
"ref_id": self.ref_id,
"label": self.label,
+ "chars": self.chars,
+ "audio_ms": self.audio_ms,
}
diff --git a/jarvis/costs/sources.py b/jarvis/costs/sources.py
index 6680852898..2e3e425a50 100644
--- a/jarvis/costs/sources.py
+++ b/jarvis/costs/sources.py
@@ -539,6 +539,8 @@ def _speech_entries(path: Path | None, since_ms: int, until_ms: int) -> Iterator
price_source=source, # type: ignore[arg-type]
ref_id=str(row["session_id"] or ""),
label=_speech_label(stage, chars, audio_ms),
+ chars=chars,
+ audio_ms=int(audio_ms),
)
except sqlite3.Error as exc:
log.warning("cost read model: speech source failed (%s)", exc)
diff --git a/jarvis/ui/web/costs_routes.py b/jarvis/ui/web/costs_routes.py
index e2c6509e87..07742be815 100644
--- a/jarvis/ui/web/costs_routes.py
+++ b/jarvis/ui/web/costs_routes.py
@@ -59,6 +59,9 @@ class Bucket(BaseModel):
entries: int
gap_tokens: int
subscription_usd: float = 0.0
+ chars: int = 0
+ """Characters synthesised — only speech rows carry these two."""
+ audio_ms: int = 0
last_ts_ms: int
cost_share: float
token_share: float
diff --git a/jarvis/ui/web/frontend/src/hooks/useCosts.ts b/jarvis/ui/web/frontend/src/hooks/useCosts.ts
index a9121215da..c57b14db59 100644
--- a/jarvis/ui/web/frontend/src/hooks/useCosts.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useCosts.ts
@@ -53,6 +53,9 @@ export interface CostBucket {
gap_tokens: number;
/** Of `cost_usd`, the part a monthly seat already paid for. */
subscription_usd: number;
+ /** Speech only: characters spoken and audio heard. Zero on token rows. */
+ chars: number;
+ audio_ms: number;
last_ts_ms: number;
cost_share: number;
token_share: number;
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 961ea0563d..644732d63c 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -5236,6 +5236,13 @@
"col_share": "Anteil",
"col_cost": "Kosten",
"col_calls": "Aufrufe",
+ "speech_models_title": "Sprachmodelle",
+ "speech_models_subtitle": "Was jedes Ohr und jeder Mund verbraucht hat, zum On-Demand-API-Preis des Anbieters — als würde jeder Aufruf einzeln abgerechnet.",
+ "speech_models_empty": "In diesem Zeitraum lief kein Sprachmodell. Sprache-zu-Sprache-Modelle haben kein eigenes Ohr und keinen eigenen Mund und tauchen hier nie auf.",
+ "col_heard": "Gehört",
+ "col_spoken": "Gesprochen",
+ "col_api_cost": "API-Kosten",
+ "col_per_call": "Pro Aufruf",
"col_when": "Wann",
"col_what": "Was",
"col_price_source": "Preis",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index e22881d489..b311d92d51 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -5236,6 +5236,13 @@
"col_share": "Share",
"col_cost": "Cost",
"col_calls": "Calls",
+ "speech_models_title": "Speech models",
+ "speech_models_subtitle": "What each ear and mouth consumed, priced at the vendor's on-demand API rate — as if every call were billed on its own.",
+ "speech_models_empty": "No speech model has run in this period. Speech-to-speech models have no separate ear or mouth and never appear here.",
+ "col_heard": "Heard",
+ "col_spoken": "Spoken",
+ "col_api_cost": "API cost",
+ "col_per_call": "Per call",
"col_when": "When",
"col_what": "What",
"col_price_source": "Price",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 3d3f22bfed..1fc57cc252 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -5234,6 +5234,13 @@
"col_share": "Parte",
"col_cost": "Coste",
"col_calls": "Llamadas",
+ "speech_models_title": "Modelos de voz",
+ "speech_models_subtitle": "Lo que consumió cada oído y cada boca, al precio de API bajo demanda del proveedor — como si cada llamada se facturara por separado.",
+ "speech_models_empty": "Ningún modelo de voz se ejecutó en este periodo. Los modelos voz a voz no tienen oído ni boca propios y nunca aparecen aquí.",
+ "col_heard": "Escuchado",
+ "col_spoken": "Hablado",
+ "col_api_cost": "Coste API",
+ "col_per_call": "Por llamada",
"col_when": "Cuándo",
"col_what": "Qué",
"col_price_source": "Precio",
diff --git a/jarvis/ui/web/frontend/src/views/CostsView.tsx b/jarvis/ui/web/frontend/src/views/CostsView.tsx
index 10f5af9b77..31aee7eba2 100644
--- a/jarvis/ui/web/frontend/src/views/CostsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/CostsView.tsx
@@ -423,6 +423,25 @@ export function CostsView() {
</div>
</Panel>
+ {/* Speech models — the speech area only ------------------------- */}
+ {area?.id === "jarvis-voice" ? (
+ <Panel>
+ <div className="px-4 pt-4">
+ <PanelHeader
+ title={t("costs_view.speech_models_title")}
+ subtitle={t("costs_view.speech_models_subtitle")}
+ />
+ </div>
+ <div className="mt-3">
+ <SpeechModelsTable
+ rows={data?.by_model ?? []}
+ money={money}
+ loading={summary.isLoading}
+ />
+ </div>
+ </Panel>
+ ) : null}
+
{/* Where it went ----------------------------------------------- */}
<Panel>
<div className="px-4 pt-4">
@@ -868,6 +887,98 @@ const ROLE_KEYS: Record<string, true> = {
worker: true,
};
+// ---------------------------------------------------------------------------
+// Speech models — what each ear and mouth consumed, at API list price
+// ---------------------------------------------------------------------------
+
+/** Audio duration in the unit a person would say it in. */
+function formatAudio(ms: number): string {
+ if (ms <= 0) return "—";
+ const s = ms / 1000;
+ if (s < 90) return `${s.toFixed(s < 10 ? 1 : 0)} s`;
+ const min = s / 60;
+ if (min < 90) return `${min.toFixed(1)} min`;
+ return `${(min / 60).toFixed(1)} h`;
+}
+
+/**
+ * One row per speech model in the area: how much it heard or spoke, how many
+ * turns that was, and what the same work costs at the vendor's on-demand API
+ * rate — total and per call. Only the speech area shows this: a brain model
+ * has tokens and the breakdown above already says everything about it, while
+ * a speech model has none, so without this table its row reads "0 tokens" and
+ * the number that matters (characters, seconds) is nowhere.
+ */
+function SpeechModelsTable({
+ rows,
+ money,
+ loading,
+}: {
+ rows: CostBucket[];
+ money: (usd: number) => string;
+ loading?: boolean;
+}) {
+ const t = useT();
+ const columns: Column[] = [
+ { id: "model", label: t("costs_view.dim_model") },
+ { id: "calls", label: t("costs_view.col_calls"), width: "84px", align: "right" },
+ { id: "heard", label: t("costs_view.col_heard"), width: "100px", align: "right" },
+ { id: "spoken", label: t("costs_view.col_spoken"), width: "110px", align: "right" },
+ { id: "cost", label: t("costs_view.col_api_cost"), width: "110px", align: "right" },
+ { id: "per_call", label: t("costs_view.col_per_call"), width: "110px", align: "right" },
+ ];
+
+ if (!loading && rows.length === 0) {
+ return (
+ <div className="px-4 pb-4">
+ <EmptyRow>{t("costs_view.speech_models_empty")}</EmptyRow>
+ </div>
+ );
+ }
+
+ return (
+ <Table label={t("costs_view.speech_models_title")}>
+ <TableHead columns={columns} />
+ {rows.map((row) => {
+ const provider = row.members[0] ?? "";
+ const perCall = row.entries > 0 ? row.cost_usd / row.entries : 0;
+ return (
+ <TableRow key={row.key} columns={columns} ariaLabel={row.key}>
+ <Cell>
+ <div className="flex min-w-0 items-center gap-2">
+ {provider ? <ProviderLogo providerId={provider} label={provider} size="sm" /> : null}
+ <div className="min-w-0">
+ <div className="truncate font-medium text-foreground">{row.key}</div>
+ {provider ? (
+ <div className="truncate text-xs text-muted-foreground">{provider}</div>
+ ) : null}
+ </div>
+ </div>
+ </Cell>
+ <Cell align="right" muted>
+ <span className="tabular-nums">{formatExact(row.entries)}</span>
+ </Cell>
+ <Cell align="right" muted>
+ <span className="tabular-nums">{formatAudio(row.audio_ms)}</span>
+ </Cell>
+ <Cell align="right" muted>
+ <span className="tabular-nums" title={formatExact(row.chars)}>
+ {row.chars > 0 ? formatTokensOrNone(row.chars) : "—"}
+ </span>
+ </Cell>
+ <Cell align="right">
+ <span className="font-medium tabular-nums text-foreground">{money(row.cost_usd)}</span>
+ </Cell>
+ <Cell align="right" muted>
+ <span className="tabular-nums">{money(perCall)}</span>
+ </Cell>
+ </TableRow>
+ );
+ })}
+ </Table>
+ );
+}
+
// ---------------------------------------------------------------------------
// Where it went — the most expensive conversations, missions and agent runs
// ---------------------------------------------------------------------------
diff --git a/tests/unit/costs/test_cost_read_model.py b/tests/unit/costs/test_cost_read_model.py
index 83b16b49df..2cbffb60f3 100644
--- a/tests/unit/costs/test_cost_read_model.py
+++ b/tests/unit/costs/test_cost_read_model.py
@@ -289,6 +289,21 @@ def test_speech_rows_with_nothing_consumed_are_dropped(tmp_path: Path) -> None:
assert len(list(collect_entries(_speech_sources(tmp_path)))) == 2
+def test_speech_rows_carry_their_quantities_and_the_buckets_sum_them(tmp_path: Path) -> None:
+ """The speech-models table needs the billed quantity as a NUMBER, per
+ model: characters spoken and audio heard ride on the entry and add up in
+ every bucket, while the token columns stay at zero."""
+ rows = {e.role: e for e in collect_entries(_speech_sources(tmp_path))}
+ assert rows["tts"].chars == 412
+ assert rows["stt"].audio_ms == 4_200 and rows["stt"].chars == 0
+
+ report = build_report(list(rows.values()), since_ms=0, until_ms=2**62)
+ by_role = {b["key"]: b for b in report.by_role}
+ assert by_role["tts"]["chars"] == 412
+ assert by_role["stt"]["audio_ms"] == 4_200
+ assert all(b["tokens_total"] == 0 for b in report.by_model)
+
+
def test_speech_keeps_the_price_the_meter_settled(tmp_path: Path) -> None:
"""The meter priced it in the vendor's unit; re-deriving it here from a
token rate would be nonsense, so its verdict must survive the read."""