Genace

generation API numeric parameters: Validate numbers before they become requests

The generation API numeric parameters contract depends on JSON types as well as numeric ranges. A browser form may display a number while its value remains a string. The provider schemas use numeric validators, so the text “5” and the number 5 are not interchangeable request values.

Start with the selected model

Image providers accept n as an integer from one through four, with a default of one. Seed is an optional integer. A fractional image count is invalid even if a client could round it. Decide whether rounding is acceptable in your own form before serialization; do not silently change a reviewed request.

Video duration rules differ. Seedance accepts integer seconds from three through fifteen. Kling accepts the numeric literals five or ten. Veo accepts the numeric literal eight. A duration that is valid for one model can fail another schema even when both requests use duration_sec.

Kling converts its already validated duration into a string inside its upstream mapping. That internal conversion does not make a public duration_sec string valid. The public contract is checked before the adapter builds the upstream request.

Parse form values explicitly

Collect the raw control value first. Reject a blank required input before converting it, because a conversion routine may turn an empty string into zero. Convert only the expected field and then check that the result is finite, integral where required, and allowed for the chosen model.

Do not apply a broad numeric conversion to the entire request. Aspect ratios and resolutions are strings, and a prompt containing numbers is still text. A field-aware builder makes these distinctions visible and avoids surprising transformations.

For optional seed, preserve numeric zero. A truthy fallback can discard it even after correct parsing. For optional duration, omission asks the provider schema to apply its default; null remains a different value and can fail validation.

Review an offline table

For image count, include missing, one, four, zero, five, a fraction, a string, and null. For each video model, add its boundary durations and at least one value accepted by a different model but rejected by the selected one.

Keep an expected outcome column that names the validation layer. A wrong JSON type should be caught locally before a paid request. An unsupported enum or duration should produce a field-specific message. No fixture needs an upstream model call to establish these properties.

Include restored draft values and URL query parameters in the review because both commonly reintroduce strings. A request builder tested only with hard-coded numeric objects can miss the actual UI path.

Acceptance criteria

Accept the numeric controls when every fixture either yields the exact approved JSON number or a clear local error. Switching models must revalidate the current duration rather than keeping a previously valid value silently.

Consult default parameters, Kling parameters, and Seedance parameters for the model-specific context behind these checks.

Continue with models and parameters

Where these facts come from

  • codebase: src/app/api/v1/images/generations/route.ts
  • codebase: src/app/api/v1/video/generations/route.ts
  • codebase: src/ai/jobs/service.ts
  • codebase: src/ai/providers/nano-banana.ts
  • codebase: src/ai/providers/seedance.ts
  • codebase: src/ai/providers/kling.ts
  • codebase: src/ai/providers/veo3.ts
  • Editorial keyword hypothesis; search volume not measured