fix: normalize aspect ratio per model, surface invalid_params in errors

Models like mystic, flux-pro-1.1, and seedream-v4/v4-5 require named
aspect ratio slugs (e.g. "square_1_1", "widescreen_16_9") while other
models accept the "W:H" format directly.

- Add normalize_aspect_ratio() mapping W:H strings to slugs for affected models
- Apply normalization in generate-image before building the request payload
- Improve FreepikAPIError to surface invalid_params field details from the API
  response, so "Validation error" now also shows which field failed and why

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-10 18:06:40 +02:00
parent e6bf85ca8a
commit d0f454df29
3 changed files with 49 additions and 3 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ import typer
from freepik_cli.api.client import FreepikAPIError, FreepikClient
from freepik_cli.api.edit import EditAPI
from freepik_cli.api.images import ImageAPI
from freepik_cli.api.models import IconStyle, ImageModel, VideoModel
from freepik_cli.api.models import IconStyle, ImageModel, VideoModel, normalize_aspect_ratio
from freepik_cli.api.videos import VideoAPI
from freepik_cli.utils.config import FreepikConfig
from freepik_cli.utils.console import GenerationResult, console, print_error, print_no_wait, print_result
@@ -86,7 +86,7 @@ def generate_image(
# Build request payload
payload: dict = {"prompt": prompt}
if aspect_ratio:
payload["aspect_ratio"] = aspect_ratio
payload["aspect_ratio"] = normalize_aspect_ratio(aspect_ratio, model)
if negative_prompt:
payload["negative_prompt"] = negative_prompt
if seed is not None: