{"record":{"id":"2815a60ada234b64","repo":"calesthio/OpenMontage","slug":"tokenhub-api-error-code-code-message-message","errorCode":null,"errorMessage":"TokenHub API error: code={code}, message={message}","messagePattern":"TokenHub API error: code=(.+?), message=(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/graphics/hunyuan_image.py","lineNumber":559,"sourceCode":"        \"\"\"Parse JSON response body or raise with HTTP status.\"\"\"\n        try:\n            return response.json()\n        except ValueError as exc:\n            raise RuntimeError(\n                f\"Non-JSON response from TokenHub API: HTTP {response.status_code}\"\n            ) from exc\n\n    @staticmethod\n    def _check_response(payload: dict[str, Any]) -> None:\n        \"\"\"Check the TokenHub API response for errors.\n\n        TokenHub returns errors at the top level with an ``error`` field.\n        \"\"\"\n        error = payload.get(\"error\")\n        if error:\n            message = error.get(\"message\", \"unknown error\")\n            code = error.get(\"code\", error.get(\"type\", \"unknown\"))\n            raise RuntimeError(\n                f\"TokenHub API error: code={code}, message={message}\"\n            )\n\n    # ------------------------------------------------------------------\n    # Output helpers\n    # ------------------------------------------------------------------\n\n    @staticmethod\n    def _resolve_output_paths(base: str, count: int) -> list[Path]:\n        \"\"\"Derive distinct paths for ``count`` images.\n\n        Single image keeps the base path unchanged; multiple images insert an\n        index before the extension (foo.png -> foo_1.png, foo_2.png, ...).\n        \"\"\"\n        base_path = Path(base)\n        if count <= 1:\n            return [base_path]\n        stem = base_path.stem","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/graphics/hunyuan_image.py#L541-L577","documentation":"RuntimeError from _check_response, the client's mapping of TokenHub top-level error objects. TokenHub returns application errors as {'error': {'message': ..., 'code'|'type': ...}} with a 200-level or 4xx status; this guard runs after every submit and poll call and converts that envelope into a readable exception.","triggerScenarios":"Invalid model name in the request body; malformed or missing required parameters caught by the API; insufficient quota/balance; authentication/permission errors expressed in-body rather than as HTTP status codes.","commonSituations":"Typo'd model identifier; free-tier quota exhausted; submitting before a required field (e.g. size/callback config) is provided; key valid for a different TokenHub product line.","solutions":["Read the code and message in the error text — they are the provider's precise complaint","For invalid-parameter errors, diff your request body against the TokenHub API docs for the exact model","For quota/billing codes, top up or switch accounts, then retry","For auth-type errors, rotate/re-verify TENCENT_TOKENHUB_API_KEY"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    data = client._json_or_raise(resp)\n    client._check_response(data)\nexcept RuntimeError as e:\n    if \"TokenHub API error\" in str(e):\n        # code+message identify the provider complaint; fix input, quota, or key accordingly","preventionTips":["Validate request bodies against per-model TokenHub docs before submitting","Watch quota/balance codes in long-running pipelines","Map known codes to actionable handling in your orchestration layer"],"tags":["hunyuan","tokenhub","api-error","validation"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}