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.

fix(cost): price the 3.5/3.6-flash generation and realtime audio tokens

Ruben Lütkece9c51bf83e0
diff --git a/jarvis/brain/cost.py b/jarvis/brain/cost.py
index 936f732f53..855fa86f81 100644
--- a/jarvis/brain/cost.py
+++ b/jarvis/brain/cost.py
@@ -55,9 +55,22 @@ PRICING_USD_PER_MTOK: dict[str, tuple[float, float]] = {
"gemini-2.5-flash": (0.075, 0.30),
"gemini-2.5-flash-lite": (0.075, 0.30),
"gemini-3.1-flash-tts-preview": (0.075, 0.30), # TTS, same rate
+ # 2026-07-28 cost audit: the 3.5/3.6 flash generation is ~20x pricier
+ # than 2.5-flash; these entries were missing, so the live install
+ # tallied its dominant spend as $0.00 (verified against the OpenRouter
+ # /api/v1/models pricing feed on 2026-07-28).
+ "gemini-3.5-flash": (1.50, 9.0),
+ "gemini-3.5-flash-lite": (0.30, 2.50),
+ "gemini-3.6-flash": (1.50, 7.50),
+ # Live API model — TEXT rates; audio rates live in
+ # REALTIME_AUDIO_PRICING_USD_PER_MTOK below.
+ "gemini-3.1-flash-live-preview": (0.75, 4.50),
# ── OpenAI (Frontier: GPT-5.5 + 5.5-pro, released 2026-04-23) ──
"gpt-5.5": (5.0, 30.0),
- "gpt-5.5-pro": (15.0, 60.0),
+ "gpt-5.5-pro": (30.0, 180.0), # corrected 2026-07-28 (OpenRouter feed)
+ # Realtime API — TEXT rates; audio rates in the realtime table below.
+ "gpt-realtime-2.1": (4.0, 16.0),
+ "gpt-realtime-2.1-mini": (0.60, 2.40),
"gpt-5": (3.0, 15.0),
"gpt-5-mini": (0.30, 1.20),
"gpt-4o": (2.50, 10.0),
@@ -75,11 +88,14 @@ PRICING_USD_PER_MTOK: dict[str, tuple[float, float]] = {
# ── DeepSeek ────────────────────────────────────────────────────
"deepseek-chat": (0.27, 1.10),
"deepseek-reasoner": (0.55, 2.19),
- # ── OpenRouter (proxied Anthropic models, same price) ──────────────
+ # ── OpenRouter (proxied models, same price as the origin) ──────────
"anthropic/claude-haiku-4.5": (0.80, 4.0),
"anthropic/claude-opus-4.8": (15.0, 75.0),
"anthropic/claude-opus-4.7": (15.0, 75.0),
"anthropic/claude-sonnet-4.6": (3.0, 15.0),
+ "google/gemini-3.5-flash": (1.50, 9.0),
+ "google/gemini-3.5-flash-lite": (0.30, 2.50),
+ "google/gemini-3.6-flash": (1.50, 7.50),
# ── Mistral (same ordering) ──────────────────────────────────────
"mistral-small-3.1": (0.20, 0.60),
"mistral-large-3": (3.0, 9.0),
@@ -113,4 +129,50 @@ def calculate_cost_usd(
return (max(0, tokens_in) * in_rate + max(0, tokens_out) * out_rate) / 1_000_000
-__all__ = ["PRICING_USD_PER_MTOK", "calculate_cost_usd"]
+# Realtime/Live API audio token rates (USD per 1M AUDIO tokens).
+# Audio tokens are billed 4-40x above the same model's text tokens, so
+# realtime cost accounting that prices everything at text rates
+# understates the bill dramatically. Sources (2026-07-28):
+# - Google Live API: gemini-3.1-flash-live-preview $3.00 in / $12.00 out
+# - OpenAI Realtime: gpt-realtime-2.1 $32 in / $64 out,
+# gpt-realtime-2.1-mini $10 in / $20 out
+REALTIME_AUDIO_PRICING_USD_PER_MTOK: dict[str, tuple[float, float]] = {
+ "gemini-3.1-flash-live-preview": (3.0, 12.0),
+ "gpt-realtime-2.1": (32.0, 64.0),
+ "gpt-realtime-2.1-mini": (10.0, 20.0),
+}
+
+
+def calculate_realtime_cost_usd(
+ model: str | None,
+ text_in: int,
+ text_out: int,
+ audio_in: int,
+ audio_out: int,
+) -> float:
+ """Return the cost of a realtime/Live turn with per-modality rates.
+
+ Text tokens use ``PRICING_USD_PER_MTOK``; audio tokens use
+ ``REALTIME_AUDIO_PRICING_USD_PER_MTOK``. A model missing from the
+ audio table falls back to its text rates for the audio share (still
+ better than 0.0), and a fully unknown model returns 0.0 like
+ :func:`calculate_cost_usd`.
+ """
+ if not model:
+ return 0.0
+ total = calculate_cost_usd(model, text_in, text_out)
+ audio_rates = REALTIME_AUDIO_PRICING_USD_PER_MTOK.get(model)
+ if audio_rates is None:
+ total += calculate_cost_usd(model, audio_in, audio_out)
+ else:
+ a_in, a_out = audio_rates
+ total += (max(0, audio_in) * a_in + max(0, audio_out) * a_out) / 1_000_000
+ return total
+
+
+__all__ = [
+ "PRICING_USD_PER_MTOK",
+ "REALTIME_AUDIO_PRICING_USD_PER_MTOK",
+ "calculate_cost_usd",
+ "calculate_realtime_cost_usd",
+]
diff --git a/tests/unit/test_brain_cost.py b/tests/unit/test_brain_cost.py
index fab6ea1015..16e8ebb221 100644
--- a/tests/unit/test_brain_cost.py
+++ b/tests/unit/test_brain_cost.py
@@ -3,7 +3,12 @@ from __future__ import annotations
import pytest
-from jarvis.brain.cost import PRICING_USD_PER_MTOK, calculate_cost_usd
+from jarvis.brain.cost import (
+ PRICING_USD_PER_MTOK,
+ REALTIME_AUDIO_PRICING_USD_PER_MTOK,
+ calculate_cost_usd,
+ calculate_realtime_cost_usd,
+)
class TestCalculateCostUsd:
@@ -81,6 +86,23 @@ class TestPricingTable:
for m in expected_models:
assert m in PRICING_USD_PER_MTOK, f"Pricing missing for {m}"
+ def test_table_has_live_install_models(self) -> None:
+ # 2026-07-28 cost audit: these are the models a current install
+ # actually runs (fast/tool tier + realtime delegates). Missing
+ # entries made the dominant spend show up as $0.00.
+ expected_models = [
+ "gemini-3.5-flash",
+ "gemini-3.5-flash-lite",
+ "gemini-3.6-flash",
+ "gemini-3.1-flash-live-preview",
+ "google/gemini-3.5-flash",
+ "google/gemini-3.6-flash",
+ "gpt-realtime-2.1",
+ "grok-4.3",
+ ]
+ for m in expected_models:
+ assert m in PRICING_USD_PER_MTOK, f"Pricing missing for {m}"
+
def test_pricing_tuple_shape(self) -> None:
for model, rates in PRICING_USD_PER_MTOK.items():
assert isinstance(rates, tuple), f"{model}: rates is not a tuple"
@@ -90,4 +112,39 @@ class TestPricingTable:
assert out_rate >= 0.0, f"{model}: output-rate negativ"
# Output is typically expected to be pricier than input
# (or equal, for flat pricing). We don't warn, just a sanity check.
- assert out_rate >= in_rate * 0.5, f"{model}: output-rate verdaechtig niedrig"
+ assert out_rate >= in_rate * 0.5, f"{model}: output rate suspiciously low"
+
+
+class TestCalculateRealtimeCostUsd:
+ def test_audio_rates_apply_for_live_model(self) -> None:
+ # 1M audio in + 1M audio out at gemini live rates: 3.0 + 12.0
+ cost = calculate_realtime_cost_usd(
+ "gemini-3.1-flash-live-preview", 0, 0, 1_000_000, 1_000_000
+ )
+ assert cost == pytest.approx(15.0)
+
+ def test_text_and_audio_combined(self) -> None:
+ # text: (1000 * 0.75 + 500 * 4.50) / 1e6 = 0.003
+ # audio: (2000 * 3.0 + 1000 * 12.0) / 1e6 = 0.018
+ cost = calculate_realtime_cost_usd(
+ "gemini-3.1-flash-live-preview", 1000, 500, 2000, 1000
+ )
+ assert cost == pytest.approx(0.021)
+
+ def test_openai_realtime_audio(self) -> None:
+ cost = calculate_realtime_cost_usd("gpt-realtime-2.1", 0, 0, 1_000_000, 0)
+ assert cost == pytest.approx(32.0)
+
+ def test_model_without_audio_entry_falls_back_to_text_rates(self) -> None:
+ # gpt-4o has no realtime audio entry -> audio share priced at text rates
+ cost = calculate_realtime_cost_usd("gpt-4o", 0, 0, 1_000_000, 0)
+ assert cost == pytest.approx(2.50)
+
+ def test_unknown_model_returns_zero(self) -> None:
+ assert calculate_realtime_cost_usd("nope", 1000, 1000, 1000, 1000) == 0.0
+ assert calculate_realtime_cost_usd(None, 1000, 1000, 1000, 1000) == 0.0
+
+ def test_audio_table_shape(self) -> None:
+ for model, rates in REALTIME_AUDIO_PRICING_USD_PER_MTOK.items():
+ assert len(rates) == 2, f"{model}: expected (in, out)"
+ assert rates[0] >= 0.0 and rates[1] >= 0.0