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:
@@ -34,10 +34,17 @@ class FreepikAPIError(Exception):
|
||||
or f"HTTP {response.status_code}"
|
||||
)
|
||||
|
||||
# Append individual field validation errors when present
|
||||
invalid = body.get("invalid_params", [])
|
||||
if invalid:
|
||||
details = "\n".join(
|
||||
f" • {p.get('field', '?')}: {p.get('reason', '')}" for p in invalid
|
||||
)
|
||||
message = f"{message}\n\n{details}"
|
||||
|
||||
hints = {
|
||||
401: "Check your API key — set FREEPIK_API_KEY or use --api-key.",
|
||||
403: "Your plan may not support this feature. Check your Freepik subscription.",
|
||||
422: "Invalid request parameters. Check the options you provided.",
|
||||
429: "Rate limit exceeded. Please wait before retrying.",
|
||||
}
|
||||
hint = hints.get(response.status_code)
|
||||
|
||||
Reference in New Issue
Block a user