Skip to content

The agent that grows with you

feat(usage): expose the decoded Codex usage payload on AccountUsageSnapshot

Teknium4ebbbde286ab
diff --git a/agent/account_usage.py b/agent/account_usage.py
index 5be58865c90..e8c31a92004 100644
--- a/agent/account_usage.py
+++ b/agent/account_usage.py
@@ -42,6 +42,9 @@ class AccountUsageSnapshot:
windows: tuple[AccountUsageWindow, ...] = ()
details: tuple[str, ...] = ()
unavailable_reason: Optional[str] = None
+ # Exact decoded provider response body (no headers/credentials) for integrations that need
+ # fields Hermes does not normalize yet. Only populated by providers that fetch a JSON body.
+ raw: Optional[dict] = None
@property
def available(self) -> bool:
@@ -436,7 +439,8 @@ def _fetch_codex_account_usage(
details.append(f"Credits balance: ${float(balance):.2f}")
elif credits.get("has_credits") and credits.get("unlimited"):
details.append("Credits balance: unlimited")
- return _snapshot("openai-codex", "usage_api", windows, details, plan=_title_case_slug(payload.get("plan_type")))
+ return _snapshot("openai-codex", "usage_api", windows, details, plan=_title_case_slug(payload.get("plan_type")),
+ raw=payload)
@dataclass(frozen=True)
diff --git a/tests/agent/test_account_usage.py b/tests/agent/test_account_usage.py
index 57bd566a4de..5566299d3ee 100644
--- a/tests/agent/test_account_usage.py
+++ b/tests/agent/test_account_usage.py
@@ -161,6 +161,23 @@ def test_codex_window_labels_follow_duration_with_positional_fallback(monkeypatc
assert [w.label for w in snapshot.windows] == ["Session", "Weekly"]
+def test_codex_snapshot_exposes_exact_raw_payload_with_one_get(monkeypatch, codex_usage_payload):
+ """#79695: the decoded body rides along untouched (unknown fields included), from the single GET."""
+ codex_usage_payload["future_field"] = {"nested": [1, 2]}
+ snapshot, calls = _explicit_creds_snapshot(monkeypatch, codex_usage_payload)
+ assert snapshot.raw == codex_usage_payload
+ assert snapshot.raw["future_field"] == {"nested": [1, 2]}
+ assert len(calls) == 1
+ assert [w.label for w in snapshot.windows] == ["Session", "Weekly"] # normalized limits unchanged
+ # Additive: existing constructor calls stay valid and default to no raw body.
+ assert account_usage.AccountUsageSnapshot(provider="anthropic", source="x", fetched_at=snapshot.fetched_at).raw is None
+
+
+def test_codex_invalid_payload_fails_closed(monkeypatch):
+ snapshot, _ = _explicit_creds_snapshot(monkeypatch, ["not", "a", "dict"])
+ assert snapshot is None
+
+
def test_codex_usage_account_id_read_failure_keeps_singleton_token(monkeypatch, codex_usage_payload):
"""When the resolver succeeds but the separate account_id read raises, the
working singleton token must still be used (best-effort account_id), NOT