calesthio/OpenMontage · error · RuntimeError
TokenHub API error: code={code}, message={message}
Error message
TokenHub API error: code={code}, message={message} What it means
Raised by _check_response when a TokenHub JSON payload carries a top-level 'error' object. This is the provider's structured error channel (mirroring OpenAI-style errors): the message and code/type from that object are embedded in the exception. It fires on both submit and poll responses, catching auth failures, invalid requests, quota issues, and model errors.
Source
Thrown at tools/video/hunyuan_cloud_video.py:528
"""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
- Read code= and message= in the exception — they name the exact provider-side problem.
- For auth errors (invalid api key), verify TENCENT_TOKENHUB_API_KEY is set correctly in the environment.
- For quota/balance errors, top up or wait for the quota window to reset.
- For invalid-parameter errors, align duration/resolution/model with TokenHub's documented allowed values.
- Retry only for rate-limit codes, with backoff.
Defensive patterns
Strategy: try-catch
Validate before calling
import os
def precheck_tokenhub_env() -> None:
key = os.environ.get("TENCENT_TOKENHUB_API_KEY")
if not key:
raise RuntimeError("TENCENT_TOKENHUB_API_KEY not set")
if inputs.get("model") not in ALLOWED_MODELS:
raise ValueError(f"unknown model: {inputs.get('model')}") Try / catch
try:
result = hunyuan_cloud_video(inputs)
except RuntimeError as e:
if "TokenHub API error" in str(e):
code = str(e).split("code=")[1].split(",")[0]
if code in ("rate_limit", "429", "too_many_requests"):
time.sleep(30); result = hunyuan_cloud_video(inputs)
elif "key" in str(e).lower() or code in ("401", "invalid_api_key"):
raise ConfigError("fix TENCENT_TOKENHUB_API_KEY") from e
else:
raise
else:
raise Prevention
- Set and sanity-check TENCENT_TOKENHUB_API_KEY before batch runs.
- Whitelist allowed model ids in your config to catch typos early.
- Parse the embedded code/message and only retry rate-limit errors.
When it happens
Trigger: Any TokenHub API call whose 200/4xx JSON body includes {error: {message, code|type}} — bad/expired TENCENT_TOKENHUB_API_KEY, unknown model name, invalid parameters, insufficient balance, or rate limiting surfaced through the error envelope.
Common situations: API key typo or revocation; account balance exhausted on TokenHub; requesting a model id the key is not entitled to; parameter validation failures (bad duration/resolution combos); note the code falls back to the 'type' field when 'code' is absent.
Related errors
- TokenHub submit returned no task id: {data}
- Non-JSON response from TokenHub API: HTTP {response.status_c
- TokenHub submit returned no task id: {data}
- TokenHub task {task_id} completed but no data.url: {data}
- TokenHub task {task_id} failed: {error_msg}
AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15).
Data as JSON: /api/errors/42b42c20fb70a70c.
Report an issue: GitHub.