{"record":{"id":"db3262f257f700de","repo":"calesthio/OpenMontage","slug":"text-exceeds-kling-tts-safety-limit-of-5000-charac","errorCode":null,"errorMessage":"text exceeds Kling TTS safety limit of 5000 characters","messagePattern":"text exceeds Kling TTS safety limit of 5000 characters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/audio/kling_tts.py","lineNumber":199,"sourceCode":"                \"format\": paths[0].suffix.lstrip(\".\") or \"mp3\",\n                \"audio_duration_seconds\": round(audio_duration, 2) if audio_duration else None,\n                \"cost_estimate_confidence\": \"low\",\n                \"cost_estimate_basis\": \"Conservative estimate pending official account-usage reconciliation.\",\n                **self._account_usage_result(inputs, client),\n                **self._callback_result_data(inputs, task_id),\n            },\n            artifacts=[str(path) for path in paths],\n            cost_usd=self.estimate_cost(inputs),\n            duration_seconds=round(time.time() - start, 2),\n            model=\"kling-official-tts\",\n        )\n\n    def _build_request(self, inputs: dict[str, Any]) -> dict[str, Any]:\n        text = str(inputs.get(\"text\") or \"\").strip()\n        if not text:\n            raise ValueError(\"text is required\")\n        if len(text) > 5000:\n            raise ValueError(\"text exceeds Kling TTS safety limit of 5000 characters\")\n\n        voice_id = str(inputs.get(\"voice_id\") or \"\").strip()\n        if not voice_id:\n            raise ValueError(\"voice_id is required for Kling official TTS\")\n\n        voice_language = str(inputs.get(\"voice_language\") or \"en\")\n        if voice_language not in TTS_LANGUAGES:\n            raise ValueError(f\"voice_language must be one of: {', '.join(TTS_LANGUAGES)}\")\n\n        voice_speed = float(inputs.get(\"voice_speed\", 1.0))\n        if voice_speed < TTS_SPEED_MIN or voice_speed > TTS_SPEED_MAX:\n            raise ValueError(f\"voice_speed must be between {TTS_SPEED_MIN} and {TTS_SPEED_MAX}\")\n\n        payload: dict[str, Any] = {\n            \"text\": text,\n            \"voice_id\": voice_id,\n            \"voice_language\": voice_language,\n            \"voice_speed\": voice_speed,","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/audio/kling_tts.py#L181-L217","documentation":"Raised by kling_tts._build_request when the stripped text exceeds 5000 characters — Kling's official TTS API hard limit. The wrapper enforces it client-side to avoid a wasted round trip and an opaque upstream rejection.","triggerScenarios":"Long narration scripts, full articles, or concatenated segments passed as a single text value longer than 5000 chars.","commonSituations":"Feeding an entire blog post or voiceover script to one TTS call; merging multiple scenes into one request; CJK text where character count hits the cap faster than expected.","solutions":["Split text into chunks under 5000 characters at sentence boundaries and make sequential calls","Use the numbered output path support (numbered_output_path) to keep chunk artifacts ordered","Compute len(text.strip()) before calling and warn in the pipeline"],"exampleFix":"// before\nresult = tool.execute({\"text\": long_script, \"voice_id\": vid})  # raises if >5000\n\n// after\nchunks = [long_script[i:i+4800] for i in range(0, len(long_script), 4800)]\nresults = [tool.execute({\"text\": c, \"voice_id\": vid}) for c in chunks]","handlingStrategy":"validation","validationCode":"text = str(inputs.get(\"text\") or \"\").strip()\nif len(text) > 5000:\n    raise ValueError(f\"text is {len(text)} chars; split into <=5000-char chunks\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk long scripts at sentence boundaries under 5000 chars","Count characters after stripping whitespace","Remember CJK scripts hit the cap with fewer words"],"tags":["kling","tts","limit","validation"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}