Skip to content

Conversation

@Dairus01
Copy link

@Dairus01 Dairus01 commented Dec 10, 2025

This PR introduces support for Fal.ai as a new generation service provider. With this integration, miners and validators can now use Fal.ai for both image and video generation tasks, expanding the available options beyond OpenAI, OpenRouter and Stability AI.

Key Changes

  • Implemented FalAIService in neurons/generator/services/fal_service.py.
  • Image generation uses the fal-ai/flux/dev model.
  • Video generation uses the fal-ai/kling-video/v1/standard/text-to-video model.
  • Added queue based polling logic to handle Fal.ai’s long running task system.
  • Updated neurons/generator/services/service_registry.py to include "fal" in SERVICE_MAP.
  • Added a comprehensive test suite in tests/generator/fal_service.py with both positive and negative test cases.

Usage
To use the Fal.ai service:

  1. Obtain an API key from Fal.ai.
  2. Set your environment variable:
    export FAL_KEY="your_api_key"
    
    
    

Note

Adds Fal.ai-based image and video generation with queue polling, integrates it into the service registry, and introduces a focused test suite.

  • Services:
    • FalAIService (neurons/generator/services/fal_service.py):
      • Supports image (model fal-ai/flux/dev) and video (model fal-ai/kling-video/v1/standard/text-to-video).
      • Implements queue-based request/Status polling, result fetching, and media download.
      • Maps common params (prompt, size, steps, seed, guidance_scale, duration, aspect_ratio) and returns bytes + metadata.
      • Requires FAL_KEY.
  • Registry:
    • Adds "fal" to SERVICE_MAP and includes Fal in API key requirement descriptions in get_all_api_key_requirements.
  • Tests:
    • tests/generator/fal_service.py: end-to-end generation tests for image/video, C2PA check for images, and invalid API key negative test.

Written by Cursor Bugbot for commit 04d8f20. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

"openrouter": OpenRouterService,
"local": LocalService,
"stabilityai": StabilityAIService
"local": LocalService,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Duplicate SERVICE_MAP entries introduced by merge error

The diff introduces duplicate entries that appear to be merge artifacts. The "local": LocalService key appears twice in SERVICE_MAP (lines 17-18), and StabilityAIService is imported twice (lines 8-9). While Python dictionaries silently overwrite duplicate keys, this indicates a merge error and the duplicate "local" entry may have been intended to be a different service entry that was lost during the merge.

Additional Locations (1)

Fix in Cursor Fix in Web

poll_interval = 2.0

while time.time() - start_time < timeout:
status_url = f"{self.base_url}/requests/{request_id}/status"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Status URL missing model path breaks polling

The status URL and result URL are constructed incorrectly. Jobs are submitted to {base_url}/{model} (e.g., https://queue.fal.run/fal-ai/flux/dev), but the status and result URLs use {base_url}/requests/{request_id} instead of {base_url}/{model}/requests/{request_id}. The model path is missing from the status and result polling endpoints, which will cause HTTP 404 errors when checking job status.

Additional Locations (1)

Fix in Cursor Fix in Web


else:
bt.logging.warning(f"Unknown Fal.ai status: {status}")
time.sleep(poll_interval)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Timeout ineffective when HTTP requests hang indefinitely

The 600-second timeout at line 124 is ineffective because the requests.get() and requests.post() calls (lines 107, 129, 138, 179) have no individual request timeouts. If any HTTP request hangs due to network issues, the code blocks indefinitely since the while loop condition at line 127 is only checked between iterations. The intended 10-minute timeout never triggers if a single request never returns.

Fix in Cursor Fix in Web

Copy link
Contributor

@dylanuys dylanuys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm whether this provides valid c2pa certs or not

@Dairus01
Copy link
Author

Yes it provides

if modality == "image":
# FLUX returns 'images': [{'url': ..., ...}]
if "images" in data and len(data["images"]) > 0:
media_url = data["images"][0]["url"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Image URL extraction lacks defensive key check

The image URL extraction at line 169 directly accesses data["images"][0]["url"] without verifying that the "url" key exists in the image object. In contrast, the video handling at lines 172-173 properly checks "url" in data["video"] before accessing it. If the API returns an image object without a "url" key, this code raises a confusing KeyError instead of falling through to the intended RuntimeError with a helpful message about "No media URL found".

Fix in Cursor Fix in Web

@Dairus01
Copy link
Author

@dylanuys please help look at this pull request, it passed all the checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants