Skip to content

The agent that grows with you

fix(pricing): resolve configured provider slugs

KoNit-Kfffd5486c9c4
diff --git a/hermes_cli/models_pricing.py b/hermes_cli/models_pricing.py
index 8409af26d17..3fc8432ee1d 100644
--- a/hermes_cli/models_pricing.py
+++ b/hermes_cli/models_pricing.py
@@ -461,7 +461,7 @@ def pricing_cache_scope(provider: str, *, current_provider: str = "", current_ba
only, never fetches: picker prewarm single-flight uses it so an endpoint rotation can start a new
worker while the previous endpoint is still slow or unreachable."""
from hermes_cli.models import _deepinfra_catalog_url, _pricing_profile_key, normalize_provider
- normalized = normalize_provider(provider)
+ normalized = normalize_provider(provider).removeprefix("custom:")
static = _STATIC_PRICING_SCOPES.get(normalized)
if static:
return static()
@@ -505,7 +505,10 @@ def get_pricing_for_provider(
normal picker opens use it so cold endpoints cannot hold the response path, while a background
prewarm fills the same caches for later opens."""
from hermes_cli.models import normalize_provider
- normalized = normalize_provider(provider)
+ # Config-defined providers use ``custom:<key>`` inventory slugs. When a
+ # key names a provider with a canonical pricing source, share that source
+ # (and its cache) rather than treating the configured row as unsupported.
+ normalized = normalize_provider(provider).removeprefix("custom:")
if cached_only:
return _cached_only_pricing(normalized)
fetcher = _PRICING_FETCHERS.get(normalized)
diff --git a/tests/hermes_cli/test_inventory_pricing.py b/tests/hermes_cli/test_inventory_pricing.py
index 60f0693191d..e6dd06962f3 100644
--- a/tests/hermes_cli/test_inventory_pricing.py
+++ b/tests/hermes_cli/test_inventory_pricing.py
@@ -436,6 +436,33 @@ def test_cached_only_pricing_returns_a_warm_value_without_fetching(monkeypatch):
) == expected
+def test_custom_provider_slug_reuses_canonical_pricing_source(monkeypatch):
+ """A configured OpenRouter row keeps both its live and warmed prices."""
+ expected = {"vendor/model": {"prompt": "0.000001", "completion": "0.000002"}}
+ fetch_calls = []
+
+ def fetcher(*, force_refresh=False):
+ fetch_calls.append(force_refresh)
+ return expected
+
+ cached_calls = []
+ monkeypatch.setitem(models_pricing._PRICING_FETCHERS, "openrouter", fetcher)
+ monkeypatch.setattr(
+ models_pricing,
+ "_cached_only_pricing",
+ lambda provider: cached_calls.append(provider) or expected,
+ )
+
+ assert models_pricing.get_pricing_for_provider("custom:openrouter") == expected
+ assert fetch_calls == [False]
+ assert models_pricing.get_pricing_for_provider("custom:openrouter", cached_only=True) == expected
+ assert cached_calls == ["openrouter"]
+ assert (
+ models_pricing.pricing_cache_scope("custom:openrouter")
+ == models_pricing.pricing_cache_scope("openrouter")
+ )
+
+
def test_cached_only_dynamic_pricing_is_profile_scoped(tmp_path, monkeypatch):
"""Alternating profiles read the endpoint each profile warmed."""
from hermes_constants import (
@@ -474,5 +501,3 @@ def test_cached_only_dynamic_pricing_is_profile_scoped(tmp_path, monkeypatch):
assert in_profile(tmp_path / "b", endpoint_b, cached_only=False) == expected_b
assert in_profile(tmp_path / "a", endpoint_b, cached_only=True) == expected_a
assert in_profile(tmp_path / "b", endpoint_a, cached_only=True) == expected_b
-
-