From e3cda5f919b48a6a06e57ee99de381289f6e1cf7 Mon Sep 17 00:00:00 2001 From: Albert Sebastian Date: Tue, 14 Apr 2026 09:56:09 +0530 Subject: [PATCH] fix(fal_ai): prevent double fal-ai/ prefix in generic model URL construction When model is configured as fal_ai/fal-ai/model-name, the provider prefix stripping leaves fal-ai/ intact, causing get_complete_url() to produce fal-ai/fal-ai/model-name. Use removeprefix() to strip it before re-adding. Co-Authored-By: Claude Opus 4.6 (1M context) --- litellm/llms/fal_ai/image_edit/transformation.py | 8 ++++---- litellm/llms/fal_ai/image_generation/transformation.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/litellm/llms/fal_ai/image_edit/transformation.py b/litellm/llms/fal_ai/image_edit/transformation.py index c8fc75211cb..b5399f50482 100644 --- a/litellm/llms/fal_ai/image_edit/transformation.py +++ b/litellm/llms/fal_ai/image_edit/transformation.py @@ -99,7 +99,9 @@ class FalAIImageEditConfig(BaseImageEditConfig): base_url = base_url.rstrip("/") # model arrives without provider prefix (e.g. "nano-banana-2/edit") # FAL API expects fal-ai/ prefix in the URL path - return f"{base_url}/fal-ai/{model}" + # Strip fal-ai/ if already present to avoid double prefix + model_path = model.removeprefix("fal-ai/") + return f"{base_url}/fal-ai/{model_path}" def _read_image_bytes( self, @@ -220,9 +222,7 @@ class FalAIImageEditConfig(BaseImageEditConfig): image_objects.append(ImageObject(url=single_image)) if not image_objects: - raise ValueError( - f"No images in Fal AI response: {response_data}" - ) + raise ValueError(f"No images in Fal AI response: {response_data}") return ImageResponse( created=int(time.time()), diff --git a/litellm/llms/fal_ai/image_generation/transformation.py b/litellm/llms/fal_ai/image_generation/transformation.py index 276452df6cc..e5e3b9d9788 100644 --- a/litellm/llms/fal_ai/image_generation/transformation.py +++ b/litellm/llms/fal_ai/image_generation/transformation.py @@ -53,7 +53,9 @@ class FalAIBaseConfig(BaseImageGenerationConfig): else: # Generic models need the model name in the URL path # model arrives without provider prefix (e.g. "nano-banana-2/edit") - complete_url = f"{complete_url}/fal-ai/{model}" + # Strip fal-ai/ if already present to avoid double prefix + model_path = model.removeprefix("fal-ai/") + complete_url = f"{complete_url}/fal-ai/{model_path}" return complete_url def validate_environment(