calesthio/OpenMontage · error · ValueError
prompt exceeds Kling image generation limit of 2500 characte
Error message
prompt exceeds Kling image generation limit of 2500 characters
What it means
ValueError raised when the prompt for a Kling image generation request exceeds 2500 characters, the documented API limit. The check runs client-side during request building, before any network call, so no quota is consumed.
Source
Thrown at tools/graphics/kling_official_image.py:268
api_family = "omni"
if api_family == "omni":
return self._build_omni_request(inputs)
return self._build_generation_request(inputs)
def _build_generation_request(self, inputs: dict[str, Any]) -> dict[str, Any]:
prompt = self._prompt(inputs)
model_name = str(inputs.get("model_name") or "kling-v3")
if model_name not in IMAGE_GENERATION_MODELS:
raise ValueError(f"model_name {model_name!r} is not supported for api_family=generation")
payload: dict[str, Any] = {
"model_name": model_name,
"prompt": prompt,
"resolution": inputs.get("resolution", "1k"),
"n": int(inputs.get("n", 1) or 1),
"aspect_ratio": inputs.get("aspect_ratio", "16:9"),
}
if len(prompt) > 2500:
raise ValueError("prompt exceeds Kling image generation limit of 2500 characters")
if inputs.get("negative_prompt"):
payload["negative_prompt"] = inputs["negative_prompt"]
image = normalize_image_input(inputs.get("image_url"), inputs.get("image_path"))
if image:
payload["image"] = image
if inputs.get("image_reference"):
payload["image_reference"] = inputs["image_reference"]
for key in ("image_fidelity", "human_fidelity"):
if inputs.get(key) is not None:
payload[key] = inputs[key]
elements = normalize_element_list(inputs.get("element_list"))
if elements:
payload["element_list"] = elements
self._copy_common_task_fields(inputs, payload)
return {
"protocol": "classic",
"path": "/v1/images/generations",
"payload": payload,View on GitHub (pinned to 95e1c3d0ab)
Solutions
- Trim the prompt to under 2500 characters; move secondary detail into negative_prompt (subject to its own limits)
- Compress verbose descriptions to the essential subject, style, and composition cues
- If using an agent, add a truncation/summarization step before the tool call
- Compute len(prompt) before invoking the tool to fail fast in your own code
Example fix
// before
inputs = {"prompt": very_long_description} // 4000 chars
// after
prompt = very_long_description[:2490].rsplit(" ", 1)[0]
inputs = {"prompt": prompt} Defensive patterns
Strategy: validation
Validate before calling
assert len(prompt) <= 2500, f"prompt is {len(prompt)} chars; Kling limit is 2500" Prevention
- Truncate or summarize agent-generated prompts before dispatch
- Move negative constraints to negative_prompt
- Add prompt length to your pre-flight validation suite
When it happens
Trigger: Passing a very long prompt (elaborate scene descriptions, pasted context, or an agent concatenating instructions) to the generation API family; prompts padded with references or negative instructions.
Common situations: LLM agents generating unbounded prompt text; concatenating prompt + style descriptors + camera notes into one string; localizing to character-heavy languages where 2500 chars arrive quickly.
Related errors
- model_name {model_name!r} is not supported for api_family=ge
- model_name {model_name!r} is not supported for api_family=om
- image_list items must be objects
- image_list items must include image, image_url, or image_pat
- element_list must be a list of element ids or objects
AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15).
Data as JSON: /api/errors/38480f99e132b422.
Report an issue: GitHub.