feat(gemini): add Gemini 4 Hydrogen and its xhigh thinking level

gemini-4-hydrogen joins the gemini provider's model list and the Google
pricing snapshot ($1.50 / $7.50 / $0.075 per 1M tokens).

Hydrogen has a fourth thinking level, xhigh. The gemini provider sends it
for the xhigh, max and ultra efforts on Hydrogen, on the Interactions,
generateContent and OpenAI-compatible surfaces; the long-decode budgets
for those efforts are unchanged. Gemini 4 Argon and Carbon reject xhigh
and keep high.
This commit is contained in:
unsupportedpastels
2026-11-12 01:01:19 +00:00
committed by Mark S.
parent 2f23ce707c
commit df7147573d
8 changed files with 68 additions and 2 deletions

View File

@@ -213,6 +213,9 @@ _SNAPSHOTS: tuple[tuple[str, Optional[str], str, dict], ...] = (
("deepseek-flash", "deepseek-v4-flash", "deepseek-chat", "deepseek-reasoner"): ("0.15", "0.60", "0.003"),
"deepseek-v4-pro": ("0.66", "1.98", "0.022"),
}),
("google", "https://ai.google.dev/gemini-api/docs/pricing", "google-pricing-2026-11-12", {
"gemini-4-hydrogen": ("1.50", "7.50", "0.075"),
}),
# Gemini 4 introductory rates through 2026-11-30; from 2026-12-01 they double ($4 / $20 / $0.20).
("google", "https://ai.google.dev/gemini-api/docs/pricing", "google-pricing-2026-11-10", {
"gemini-4-carbon": ("2.00", "10.00", "0.10"),

View File

@@ -235,7 +235,7 @@ _PROVIDER_MODELS: dict[str, list[str]] = _CuratedCatalog({
"xai-oauth": _xai_finalize_catalog(list(_XAI_STATIC_FALLBACK)),
"gemini": [
# Gemini 4 after it: [0] is the silent default when no model is configured, and a flagship never is.
"gemini-3.8-flash", "gemini-4-carbon", "gemini-4-argon", "gemini-3.7-flash",
"gemini-3.8-flash", "gemini-4-hydrogen", "gemini-4-carbon", "gemini-4-argon", "gemini-3.7-flash",
"gemini-3.1-pro-preview", "gemini-3-pro-preview", "gemini-3.6-flash", "gemini-3.1-flash-lite-preview",
],
"zai": [

View File

@@ -14,6 +14,21 @@ from providers.base import ProviderProfile
logger = logging.getLogger(__name__)
# Models that take the ``xhigh`` thinking level; Gemini 4 Argon and Carbon answer 400 to it.
_XHIGH_MODELS = ("gemini-4-hydrogen",)
_XHIGH_EFFORTS = {"xhigh", "max", "ultra"}
def _with_top_thinking_level(model: str, reasoning_config: Any, thinking_config: dict[str, Any]) -> dict[str, Any]:
"""Send ``xhigh`` where the model has it: the shared mapping stops at ``high``, the top level of the
other thinking-level models."""
name = (model or "").strip().lower().removeprefix("google/")
effort = str(reasoning_config.get("effort") or "").strip().lower() if isinstance(reasoning_config, dict) else ""
if name.startswith(_XHIGH_MODELS) and effort in _XHIGH_EFFORTS and thinking_config.get("thinkingLevel") == "high":
return {**thinking_config, "thinkingLevel": "xhigh"}
return thinking_config
class GeminiProfile(ProviderProfile):
"""Gemini — translate reasoning_config to thinking_config in extra_body."""
@@ -29,6 +44,7 @@ class GeminiProfile(ProviderProfile):
raw = _build_gemini_thinking_config(context.get("model") or "", context.get("reasoning_config"))
if not raw:
return {}
raw = _with_top_thinking_level(context.get("model") or "", context.get("reasoning_config"), raw)
base_url = context.get("base_url") or self.base_url
if self.name == "gemini" and _is_gemini_openai_compat_base_url(base_url):
thinking_config = _snake_case_gemini_thinking_config(raw)

View File

@@ -46,7 +46,7 @@ logger = logging.getLogger(__name__)
# One request's output cap (streamed hops get 64K; unary 32K). A budget above it needs continuation hops.
SINGLE_REQUEST_OUTPUT_CAP = 65_536
_THINKING_LEVELS = {"minimal", "low", "medium", "high"}
_THINKING_LEVELS = {"minimal", "low", "medium", "high", "xhigh"}
_TOOL_CHOICES = {"auto": "auto", "required": "any", "none": "none"}
_IMAGE_MIME_TYPES = {"image/png", "image/jpeg", "image/webp", "image/heic", "image/heif", "image/gif", "image/bmp", "image/tiff"}
# Interaction.status -> OpenAI finish_reason (requires_continuation is consumed by the hop loop).

View File

@@ -92,6 +92,29 @@ def test_gemini4_maps_effort_to_thinking_level_and_long_decode_budget(reasoning,
assert "max_output_tokens" not in compat
@pytest.mark.parametrize(
"model,effort,level,budget",
[
("gemini-4-hydrogen", "medium", "medium", None),
("gemini-4-hydrogen", "high", "high", None),
("gemini-4-hydrogen", "xhigh", "xhigh", 262_144),
("google/gemini-4-hydrogen", "max", "xhigh", 1_048_576),
("gemini-4-carbon", "xhigh", "high", 262_144), # Argon and Carbon answer 400 to xhigh
],
)
def test_gemini_provider_sends_xhigh_only_to_the_models_that_take_it(model, effort, level, budget):
from providers import get_provider_profile
profile = get_provider_profile("gemini")
native = profile.build_extra_body(model=model, reasoning_config={"enabled": True, "effort": effort},
base_url="https://generativelanguage.googleapis.com/v1beta")
assert native["thinking_config"] == {"includeThoughts": True, "thinkingLevel": level}
assert native.get("max_output_tokens") == budget
hidden = profile.build_extra_body(model=model, reasoning_config={"enabled": False, "effort": effort},
base_url="https://generativelanguage.googleapis.com/v1beta")
assert hidden["thinking_config"] == {"includeThoughts": False, "thinkingLevel": "low"}
@pytest.mark.parametrize(
"model,effort,level",
[

View File

@@ -408,6 +408,17 @@ def test_curated_google_flash_models_resolve_official_snapshot_pricing(monkeypat
assert model in _PROVIDER_MODELS["vertex"], model
def test_gemini_4_hydrogen_is_pickable_and_priced(monkeypatch):
from hermes_cli.models_catalog_static import _PROVIDER_MODELS
monkeypatch.setattr("agent.usage_pricing.fetch_endpoint_model_metadata", lambda *_args, **_kwargs: {})
usage = CanonicalUsage(input_tokens=1_000_000, output_tokens=1_000_000, cache_read_tokens=1_000_000)
cost = estimate_usage_cost("gemini-4-hydrogen", usage, provider="gemini")
assert "gemini-4-hydrogen" in _PROVIDER_MODELS["gemini"] and _PROVIDER_MODELS["gemini"][0] == "gemini-3.8-flash"
assert (cost.status, cost.source) == ("estimated", "official_docs_snapshot")
assert str(cost.amount_usd) == "9.075" # 1.50 + 7.50 + 0.075
def test_gemini_4_carbon_is_pickable_and_prices_like_argon(monkeypatch):
from hermes_cli.models_catalog_static import _PROVIDER_MODELS

View File

@@ -53,6 +53,14 @@ HISTORY = [
]
def test_xhigh_thinking_level_reaches_the_request(gemini):
_, wire = gemini
request = wire.build_interactions_request(
model="gemini-4-hydrogen", messages=[{"role": "user", "content": "hi"}],
thinking_config={"thinkingLevel": "xhigh", "includeThoughts": True})
assert request["generation_config"]["thinking_level"] == "xhigh"
def test_request_is_stateless_typed_steps_with_signatures_replayed_as_thought_steps(gemini):
_, wire = gemini
request = wire.build_interactions_request(

View File

@@ -183,6 +183,7 @@ The `hermes model` picker shows Gemini models maintained in Hermes' provider reg
| Model | ID | Notes |
|-------|----|-------|
| Gemini 4 Hydrogen | `gemini-4-hydrogen` | Fast Gemini 4 model for everyday coding and agentic work; same window and long decode as Argon, plus an `xhigh` thinking level. Free and paid tiers |
| Gemini 4 Carbon | `gemini-4-carbon` | Strongest reasoning model; spends more thinking per turn than Argon, with the same window, long decode and price. Paid tier only |
| Gemini 4 Argon | `gemini-4-argon` | Flagship reasoning model; shared 1M input+output window, long decode up to 1M output tokens |
| Gemini 3.8 Flash | `gemini-3.8-flash` | Most capable Flash model for long-horizon agentic and coding work |
@@ -211,6 +212,10 @@ Gemini 4 Carbon works the same way as Argon in everything below. Gemini 4 Argon
| `xhigh` | `high` | 262,144 tokens (long decode) |
| `max`, `ultra` | `high` | 1,048,576 tokens minus the input (long decode) |
Gemini 4 Hydrogen has a fourth level, `xhigh`: on Hydrogen, Hermes sends `xhigh` for the
`xhigh`, `max` and `ultra` efforts, with the same output budgets as above. Google's own default
level for Hydrogen is `high`.
Without long decode a single request stops at 65,536 output tokens when streaming
(32,768 non-streaming), thinking included. With `xhigh` or `max`, Hermes raises
`maxOutputTokens` and, when a request reaches the per-request cap with budget left