fix: skip aspect_ratio for kling-o1 models and detect image MIME via Pillow
kling-o1-pro and kling-o1-std silently fail when aspect_ratio is included in the payload — they derive it from the input image. Added VIDEO_ASPECT_RATIO_MODELS whitelist so only kling-elements and minimax-hailuo receive the parameter. Also switched image_to_base64 to use Pillow for format detection instead of trusting the file extension, which correctly handles files saved with the wrong extension. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -107,7 +107,14 @@ VIDEO_IMAGE_FIELDS: dict[VideoModel, str] = {
|
||||
VideoModel.MINIMAX_HAILUO: "image",
|
||||
}
|
||||
|
||||
# Kling Elements requires named aspect ratio slugs
|
||||
# Models that support an aspect_ratio parameter at all
|
||||
VIDEO_ASPECT_RATIO_MODELS: set[VideoModel] = {
|
||||
VideoModel.KLING_ELEMENTS_PRO,
|
||||
VideoModel.KLING_ELEMENTS_STD,
|
||||
VideoModel.MINIMAX_HAILUO,
|
||||
}
|
||||
|
||||
# Of those, these require named slug aspect ratios instead of "W:H" strings
|
||||
VIDEO_SLUG_ASPECT_RATIO_MODELS: set[VideoModel] = {
|
||||
VideoModel.KLING_ELEMENTS_PRO,
|
||||
VideoModel.KLING_ELEMENTS_STD,
|
||||
|
||||
@@ -9,7 +9,7 @@ from freepik_cli.api.models import (
|
||||
VIDEO_POST_ENDPOINTS,
|
||||
VIDEO_STATUS_ENDPOINTS,
|
||||
VIDEO_IMAGE_FIELDS,
|
||||
VIDEO_SLUG_ASPECT_RATIO_MODELS,
|
||||
VIDEO_ASPECT_RATIO_MODELS,
|
||||
VideoModel,
|
||||
get_output_urls,
|
||||
get_status,
|
||||
@@ -49,7 +49,7 @@ class VideoAPI:
|
||||
effective_duration = 6
|
||||
payload["duration"] = str(effective_duration)
|
||||
|
||||
if aspect_ratio:
|
||||
if aspect_ratio and model in VIDEO_ASPECT_RATIO_MODELS:
|
||||
payload["aspect_ratio"] = normalize_aspect_ratio_video(aspect_ratio, model)
|
||||
|
||||
if seed is not None:
|
||||
|
||||
Reference in New Issue
Block a user