calesthio/OpenMontage · error · RuntimeError
Non-JSON response from TokenHub API: HTTP {response.status_c
Error message
Non-JSON response from TokenHub API: HTTP {response.status_code} What it means
Raised by _json_or_raise when a TokenHub HTTP response body is not valid JSON (response.json() raises ValueError). The tool wraps the parse failure with the HTTP status code so you can tell an HTML error page (502/503 from a gateway) from a 200 with a malformed body.
Source
Thrown at tools/video/hunyuan_cloud_video.py:514
# ------------------------------------------------------------------
@staticmethod
def _safe_error(exc: Exception) -> str:
"""Redact secret values from exception messages."""
msg = str(exc)
for var in ("TENCENT_TOKENHUB_API_KEY",):
val = os.environ.get(var, "")
if val:
msg = msg.replace(val, "[redacted]")
return msg
@staticmethod
def _json_or_raise(response: Any) -> dict[str, Any]:
"""Parse JSON response body or raise with HTTP status."""
try:
return response.json()
except ValueError as exc:
raise RuntimeError(
f"Non-JSON response from TokenHub API: HTTP {response.status_code}"
) from exc
@staticmethod
def _check_response(payload: dict[str, Any]) -> None:
"""Check the TokenHub API response for errors.
TokenHub returns errors at the top level with an ``error`` field.
"""
error = payload.get("error")
if error:
message = error.get("message", "unknown error")
code = error.get("code", error.get("type", "unknown"))
raise RuntimeError(
f"TokenHub API error: code={code}, message={message}"
)
View on GitHub (pinned to 95e1c3d0ab)
Solutions
- Retry with backoff — transient gateway errors are the most common cause and usually self-heal.
- If reproducing consistently, capture response.text to see what the body actually is (WAF page, maintenance notice) before parsing.
- Shrink the request payload (see the 6 MB image cap, error 249) if a WAF is rejecting large bodies.
- Bypass intermediary proxies for the TokenHub host if one is in the path.
Defensive patterns
Strategy: retry
Try / catch
last_err = None
for attempt in range(3):
try:
result = hunyuan_cloud_video(inputs)
break
except RuntimeError as e:
if "Non-JSON response" in str(e):
last_err = e
time.sleep(2 ** attempt * 5) # gateway hiccup: backoff and retry
else:
raise
else:
raise last_err Prevention
- Wrap TokenHub calls in exponential-backoff retry for non-JSON/gateway errors.
- Keep request payloads small (see the 6MB image cap) to avoid WAF rejections.
- Avoid routing TokenHub traffic through body-rewriting proxies.
When it happens
Trigger: Any TokenHub request (submit or poll) whose response is HTML/XML/plain text — gateway 502/504 pages, WAF block pages, maintenance notices, or empty bodies on dropped connections.
Common situations: TokenHub gateway briefly restarting or overloaded; a WAF rejecting the request (large base64 payloads tripping rules); corporate proxies intercepting the connection; provider maintenance windows returning HTML.
Related errors
- TokenHub submit returned no task id: {data}
- TokenHub task {task_id} completed but no data[].url: {data}
- TokenHub task {task_id} failed: {error_msg}
- TokenHub task {task_id} returned unknown status: {status}
- TokenHub task {task_id} did not finish within {timeout_secon
AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15).
Data as JSON: /api/errors/71b7eb8e92f5a118.
Report an issue: GitHub.