The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(nous): unlock subscription-billed models for free-tier accounts
Robin Fernandesa76e4916605c
diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex b3712cbd1fd..f33aea29ff9 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -215,8 +215,10 @@ def _zero_priced(pricing: Any, keys: tuple[str, str], default: str) -> bool:def _is_model_free(model_id: str, pricing: dict[str, dict[str, str]]) -> bool:- """Return True if *model_id* has zero-cost prompt AND completion pricing."""- return bool(pricing.get(model_id)) and _zero_priced(pricing.get(model_id), ("prompt", "completion"), "1")+ """Return True if *model_id* costs no credits: zero-cost prompt AND completion pricing, or a row+ the gateway bills to a subscription."""+ entry = pricing.get(model_id)+ return bool(entry) and (entry.get("billing_mode") == "subscription" or _zero_priced(entry, ("prompt", "completion"), "1"))def partition_nous_models_by_tier(@@ -484,6 +486,8 @@ def recommended_nous_default_model() -> dict[str, Any]:model_ids = mp.restrict_to_nous_policy(model_ids, policy_allowed, rescue_empty=True)if free_tier:model_ids, _unavailable = partition_nous_models_by_tier(model_ids, pricing, free_tier=True)+ # Never default onto a subscription-billed row: spending that plan is the user's call.+ model_ids = [mid for mid in model_ids if not pricing.get(mid, {}).get("billing_mode")] or model_idsreturn {"provider": "nous", "model": pick_silent_default_model(model_ids, provider="nous"),"free_tier": bool(free_tier)}diff --git a/hermes_cli/models_pricing.py b/hermes_cli/models_pricing.pyindex a87652fea94..d681678082c 100644--- a/hermes_cli/models_pricing.py+++ b/hermes_cli/models_pricing.py@@ -243,6 +243,9 @@ def fetch_models_with_pricing(if original.get(key) not in (None, "")}if orig_entry.get("prompt") or orig_entry.get("completion"):entry["original"] = orig_entry+ # Nous Portal-only: the gateway bills this row to a subscription the account holds, not to credits.+ if include_sale_original and item.get("billing_mode") == "subscription":+ entry["billing_mode"] = "subscription"result[mid] = entryreturn _cache_catalog(cache_key, result, cache_ttl_seconds)diff --git a/tests/agent/test_credits_policy.py b/tests/agent/test_credits_policy.pyindex d7db358e898..78592a725df 100644--- a/tests/agent/test_credits_policy.py+++ b/tests/agent/test_credits_policy.py@@ -326,6 +326,7 @@ class TestIsFreeTierModel:"https://inference-api.nousresearch.com": {"some/zero-priced": {"prompt": "0", "completion": "0"},"some/paid": {"prompt": "0.000001", "completion": "0.000002"},+ "some/subscription": {"prompt": "0.000001", "completion": "0.000002", "billing_mode": "subscription"},}},)@@ -334,6 +335,7 @@ class TestIsFreeTierModel:base = "https://inference-api.nousresearch.com/v1"assert is_free_tier_model("some/zero-priced", base) is Trueassert is_free_tier_model("some/paid", base) is False+ assert is_free_tier_model("some/subscription", base) is True # billed elsewhere: depleted credits don't block it# Pre-stripped and trailing-slash variants resolve to the same key.assert is_free_tier_model("some/zero-priced", "https://inference-api.nousresearch.com/") is Trueassert is_free_tier_model("some/zero-priced", "https://inference-api.nousresearch.com/v1/") is Truediff --git a/tests/hermes_cli/test_models.py b/tests/hermes_cli/test_models.pyindex de8a592ff64..59726061b2c 100644--- a/tests/hermes_cli/test_models.py+++ b/tests/hermes_cli/test_models.py@@ -182,6 +182,27 @@ class TestPartitionNousModelsByTier:assert unav == []+ def test_subscription_billed_model_is_selectable_on_free_tier(self):+ """A row the gateway bills to a subscription costs no credits, whatever price it lists."""+ models = ["anthropic/claude-opus-4.6", "openai/gpt-5.4"]+ pricing = {"anthropic/claude-opus-4.6": self._PAID, "openai/gpt-5.4": {**self._PAID, "billing_mode": "subscription"}}+ sel, unav = partition_nous_models_by_tier(models, pricing, free_tier=True)+ assert (sel, unav) == (["openai/gpt-5.4"], ["anthropic/claude-opus-4.6"])++ def test_free_tier_default_prefers_a_free_model_over_a_subscription_billed_one(self, monkeypatch):+ import hermes_cli.models as m+ from hermes_cli import models_pricing as mp+ pricing = {"openai/gpt-5.4": {**self._PAID, "billing_mode": "subscription"}, "free/model": self._FREE}+ monkeypatch.setattr(m, "get_curated_nous_model_ids", lambda: list(pricing))+ monkeypatch.setattr(m, "check_nous_free_tier", lambda **kw: True)+ monkeypatch.setattr(m, "union_with_portal_free_recommendations", lambda ids, pr, url="", **kw: (ids, pr))+ monkeypatch.setattr(m, "get_preferred_silent_default_model", lambda provider="": "not/listed")+ monkeypatch.setattr(mp, "get_pricing_for_provider", lambda slug, **kw: pricing)+ monkeypatch.setattr(mp, "nous_policy_allowed_ids", lambda **kw: None)+ assert m.recommended_nous_default_model()["model"] == "free/model"+ del pricing["free/model"]+ assert m.recommended_nous_default_model()["model"] == "openai/gpt-5.4"+def test_all_paid_models(self):"""When all models are paid, free-tier users have none selectable."""models = ["anthropic/claude-opus-4.6", "openai/gpt-5.4"]diff --git a/tests/hermes_cli/test_sale_pricing.py b/tests/hermes_cli/test_sale_pricing.pyindex f4dc6cf2559..ec7020359dd 100644--- a/tests/hermes_cli/test_sale_pricing.py+++ b/tests/hermes_cli/test_sale_pricing.py@@ -81,6 +81,19 @@ def test_fetch_models_with_pricing_copies_nested_original(monkeypatch):assert "original" not in result["free/model"]+def test_fetch_models_with_pricing_copies_billing_mode_for_nous_only(monkeypatch):+ payload = {"data": [{"id": "a/b", "billing_mode": "subscription", "pricing": {"prompt": "0.000002", "completion": "0.00001"}}]}+ resp = MagicMock()+ resp.read.return_value = json.dumps(payload).encode()+ resp.__enter__ = lambda self: self+ resp.__exit__ = lambda *a: False+ monkeypatch.setattr(models_mod, "_urlopen_model_catalog_request", lambda req, timeout=8.0: resp)++ fetch = lambda **kw: fetch_models_with_pricing(api_key="sk-test", base_url="https://example.test", force_refresh=True, **kw)+ assert fetch(include_sale_original=True)["a/b"]["billing_mode"] == "subscription"+ assert "billing_mode" not in fetch()["a/b"]++def test_resolve_nous_pricing_credentials_honors_inference_env_override(monkeypatch):