feat: log remaining credits after Nano Banana completion

This commit is contained in:
Steve Tietze
2025-12-17 20:10:40 +07:00
parent b4a2cf25a0
commit dd06e4c026
+18
View File
@@ -67,6 +67,22 @@ def _log(enabled: bool, msg: str) -> None:
print(f"[KIE] {msg}")
def _log_remaining_credits(log: bool, record_data: dict[str, Any], api_key: str) -> None:
if not log:
return
remaining = record_data.get("remainedCredits")
if remaining is not None:
_log(True, f"Remaining credits: {remaining}")
return
try:
_raw, credits_remaining = _fetch_remaining_credits(api_key)
_log(True, f"Remaining credits: {credits_remaining}")
except Exception as exc:
_log(True, f"Failed to fetch remaining credits: {exc}")
def _truncate_url(url: str, max_length: int = 80) -> str:
if len(url) <= max_length:
return url
@@ -462,6 +478,8 @@ class KIE_NanoBananaPro_Image:
image_tensor = _image_bytes_to_tensor(image_bytes)
_log(log, "Image downloaded and decoded.")
_log_remaining_credits(log, record_data, api_key)
return (image_tensor,)
except TransientKieError as exc:
if not retry_on_fail or attempt >= attempts: