calesthio/OpenMontage · error · ValueError

custom_price_cny_per_million_tokens must be a finite number

Error message

custom_price_cny_per_million_tokens must be a finite number greater than 0

What it means

First of two identical-message branches in `_get_custom_price`: this one fires when `float(raw)` raises TypeError/ValueError, i.e. the supplied `custom_price_cny_per_million_tokens` is not parseable as a number at all — a string like `"cheap"`, a list, None, or similar. The second branch (error 288) covers values that parse but are non-finite or non-positive.

Source

Thrown at tools/video/seedance_ark.py:436

    def estimate_cost(self, inputs: dict[str, Any]) -> float:
        cny_per_usd = self._get_cny_per_usd()
        return round(self.estimate_cost_cny(inputs) / cny_per_usd, 4)

    @staticmethod
    def _get_custom_price(inputs: dict[str, Any], *, required: bool) -> float:
        try:
            raw = inputs["custom_price_cny_per_million_tokens"]
        except KeyError as exc:
            if not required:
                return 0.0
            raise ValueError(
                "pricing is unknown for a custom Ark Endpoint/Model; "
                "set custom_price_cny_per_million_tokens before a paid create"
            ) from exc
        try:
            value = float(raw)
        except (TypeError, ValueError) as exc:
            raise ValueError(
                "custom_price_cny_per_million_tokens must be a finite "
                "number greater than 0"
            ) from exc
        if not math.isfinite(value) or value <= 0:
            raise ValueError(
                "custom_price_cny_per_million_tokens must be a finite "
                "number greater than 0"
            )
        return value

    @staticmethod
    def _get_cny_per_usd() -> float:
        try:
            value = float(os.environ.get("ARK_CNY_PER_USD", "7.2"))
        except (TypeError, ValueError) as exc:
            raise ValueError(
                "ARK_CNY_PER_USD must be a finite number greater than 0"
            ) from exc

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. Pass a bare number (or numeric string) with no units or symbols: `15.0` not `"15 CNY/MTok"`
  2. Validate `float(value)` in your own code before calling the tool
  3. Check for stray quotes in JSON/YAML config where the value is defined

Example fix

# before
inputs = {"custom_price_cny_per_million_tokens": "15 CNY per Mtok"}
# after
inputs = {"custom_price_cny_per_million_tokens": 15.0}
Defensive patterns

Strategy: validation

Validate before calling

raw = inputs.get("custom_price_cny_per_million_tokens")
if raw is not None:
    try:
        float(raw)
    except (TypeError, ValueError) as e:
        raise ValueError(f"price {raw!r} is not numeric") from e

Type guard

def is_numeric_price(v: object) -> bool:
    try:
        return float(v) == float(v)  # NaN check via self-equality
    except (TypeError, ValueError):
        return False

Try / catch

try:
    result = ark.execute(inputs)
except ValueError as e:
    if "finite number" in str(e):
        raise ValueError(f"bad custom_price input: {inputs.get('custom_price_cny_per_million_tokens')!r}") from e
    raise

Prevention

When it happens

Trigger: Passing `custom_price_cny_per_million_tokens` as a non-numeric string ("0.15元"), None, a dict/list, or a bool-bearing expression that does not coerce; JSON payloads where the value arrives quoted.

Common situations: Config files or LLM-generated inputs that quote the number; currency symbols or units accidentally embedded in the value; templating systems substituting an empty/None placeholder.

Related errors


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