Snap a requested video length to supported durations in Python

Veo 3.1 accepts only 4, 6 or 8 seconds. A short Python helper snaps any requested length to a model's supported_durations list from GET /v1/videos/models.

4 min readSume
All posts

Snap the requested length to the nearest value in the model's duration list before you submit, so an odd request such as 7 seconds does not fail. Veo 3.1 on the Gemini API accepts 4, 6 or 8 seconds, and Sume publishes each video model's list as supported_durations at GET /v1/videos/models.

Limits differ by model

Duration limits are not uniform. The Veo guide lists 4, 6 and 8 seconds, and says 8 seconds is required for 1080p, 4K and reference images. On Sume, the docs list seedance-2.5 at 4 to 30 seconds, wan-3.0 at 2 to 30, minimax-h3 at 5 to 15 and gemini-omni-flash-1.1 at 3 to 10.

Duration limits (read 2026-10-03)
ModelAllowed lengthsSource
Veo 3.1 (Gemini API)4, 6 or 8 sGoogle Veo guide
seedance-2.5 (Sume)4 to 30 sSume video docs
wan-3.0 (Sume)2 to 30 sSume video docs
minimax-h3 (Sume)5 to 15 sSume video docs
gemini-omni-flash-1.1 (Sume)3 to 10 sSume video docs

The helper

The function picks the closest allowed value and, on a tie, the longer one so a caption or voiceover is not cut. The block runs as written and needs no network access.

def snap_duration(requested, supported):
    if not supported:
        raise ValueError('model lists no supported_durations')
    return min(supported, key=lambda d: (abs(d - requested), -d))

def main():
    veo = [4, 6, 8]
    seedance = list(range(4, 31))
    for want in (3, 5, 7, 12):
        print(want, '->', snap_duration(want, veo), snap_duration(want, seedance))

if __name__ == '__main__':
    main()

Reading the list from Sume

To use live data, call GET /v1/videos/models with your bearer key, find your model by id, and pass its supported_durations to the helper. Do the same check for supported_resolutions and supported_aspect_ratios. The request shape is in the video docs. If you send a value the model rejects you get a 400, so snapping first saves a round trip.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume