calesthio/OpenMontage · error · ValueError

element_id must be an integer-compatible value: {raw_id!r}

Error message

element_id must be an integer-compatible value: {raw_id!r}

What it means

Raised when the extracted element id cannot be converted with int(raw_id). int() accepts ints, floats, and numeric strings, but fails on non-numeric strings ('abc'), None is caught earlier, and values like '12.5' or '1_2' also raise. The original value is included in the message via repr.

Source

Thrown at tools/_kling/elements.py:36

    if not element_list:
        return []
    if not isinstance(element_list, list):
        raise ValueError("element_list must be a list of element ids or objects")

    normalized: list[dict[str, int]] = []
    for item in element_list:
        raw_id: Any
        if isinstance(item, dict):
            raw_id = item.get("element_id", item.get("id"))
        else:
            raw_id = item
        if raw_id is None:
            raise ValueError("each element_list item must include element_id")
        try:
            element_id = int(raw_id)
        except (TypeError, ValueError) as exc:
            raise ValueError(f"element_id must be an integer-compatible value: {raw_id!r}") from exc
        if element_id <= 0:
            raise ValueError("element_id must be positive")
        normalized.append({"element_id": element_id})
    return normalized


def element_ids(element_list: Any | None) -> list[int]:
    """Return normalized element ids from an element reference list."""

    return [item["element_id"] for item in normalize_element_list(element_list)]


def get_custom_element(element_id: int, client: KlingClient | None = None) -> dict[str, Any]:
    """Fetch one custom element for validation or diagnostics."""

    api = client or KlingClient()
    return api.get(f"/v1/general/advanced-custom-elements/{int(element_id)}")

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. Use the integer id returned by the custom-element creation endpoint (get_custom_element shows the expected shape)
  2. Strip non-numeric prefixes/suffixes before passing if your source adds them
  3. If ids can genuinely be non-integer in your flow, stop using normalize_element_list and pass the official element_list format directly to the API

Example fix

// before
refs = normalize_element_list(['elm_0000123'])

// after
refs = normalize_element_list([123])  # integer id from the element creation response
Defensive patterns

Strategy: validation

Validate before calling

def is_int_like_id(value) -> bool:
    if isinstance(value, bool):
        return False
    if isinstance(value, int):
        return True
    if isinstance(value, str):
        return value.strip().lstrip('+-').isdigit()
    return False

Type guard

def to_element_id(value):
    try:
        return int(value)
    except (TypeError, ValueError):
        return None  # explicit None => caller rejects instead of crashing

Try / catch

try:
    refs = normalize_element_list(items)
except ValueError as e:
    if 'integer-compatible' in str(e):
        raise ValueError('element ids must be integers from the element-creation API, not slugs/uuids') from e
    raise

Prevention

When it happens

Trigger: Passing a UUID or slug string as an element id ('elm_abc123'); a float string like '12.5'; a dict whose element_id value is itself a dict/list; ids from a different API that are alphanumeric rather than integer.

Common situations: Confusing custom-element ids (integers) with other Kling resource ids (task ids, which are strings); pasting ids from a UI that appends formatting; LLM hallucinating id formats.

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/792577a2f49fac45. Report an issue: GitHub.