Skip to content

feat: add MuAPI video generation tool#196

Open
Anil-matcha wants to merge 3 commits into
video-db:mainfrom
Anil-matcha:feat/muapi-video-tool
Open

feat: add MuAPI video generation tool#196
Anil-matcha wants to merge 3 commits into
video-db:mainfrom
Anil-matcha:feat/muapi-video-tool

Conversation

@Anil-matcha

@Anil-matcha Anil-matcha commented Jun 17, 2026

Copy link
Copy Markdown

Summary

Adds a new video generation tool backed by muapi.ai — a generative media API aggregator that provides unified access to 400+ models across multiple providers.

What this adds

  • backend/director/tools/muapi_video.pyMuApiVideoGenerationTool class with text_to_video() and image_to_video() methods
  • Follows the same pattern as existing tools (fal_video.py, kling.py, etc.)
  • Supports text-to-video: Veo3, Kling, Wan, Seedance, Runway, Pixverse, HunyuanVideo, Minimax and more
  • Supports image-to-video: Kling, Wan, Seedance, Runway, Pixverse, Vidu, HunyuanVideo and more
  • Async submit → poll pattern matching muapi's API contract

Usage

tool = MuApiVideoGenerationTool(api_key=os.environ["MUAPI_API_KEY"])

# Text to video
tool.text_to_video(
    prompt="A drone shot over a mountain lake at sunrise",
    save_at="output.mp4",
    duration=5,
    config={"model_name": "veo3-fast"},
)

# Image to video
tool.image_to_video(
    image_url="https://example.com/photo.jpg",
    save_at="output.mp4",
    duration=5,
    config={"model_name": "kling-master"},
    prompt="pan right slowly",
)

Get an API key at muapi.ai/dashboard/api-keys.

Summary by CodeRabbit

  • New Features
    • Added video generation from text prompts, including configurable duration and aspect ratio options.
    • Added video generation from image URLs, with an optional prompt to guide the output.
    • Integrated support for multiple model options via model-specific endpoints, including automatic endpoint fallback for image-based video generation.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b051fa8-d9c9-457c-8737-86447b41eafc

📥 Commits

Reviewing files that changed from the base of the PR and between 6e3aff4 and ef773c6.

📒 Files selected for processing (1)
  • backend/director/tools/muapi_video.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/director/tools/muapi_video.py

📝 Walkthrough

Walkthrough

A new MuApiVideoGenerationTool is added in backend/director/tools/muapi_video.py with endpoint mappings, request submission and polling helpers, and public text-to-video and image-to-video methods that download generated video bytes to save_at.

Changes

MuApi Video Generation Tool

Layer / File(s) Summary
Config constants and endpoint mappings
backend/director/tools/muapi_video.py
Defines PARAMS_CONFIG for model, duration, and aspect ratio inputs for both generation modes; T2V_ENDPOINTS and I2V_ENDPOINTS map model names to muapi endpoint identifiers.
Session setup, _submit, and _poll
backend/director/tools/muapi_video.py
__init__ stores the API key in a persistent requests.Session header; _submit POSTs a generation request and returns request_id; _poll loops on GET until completed, failed/cancelled (raises), or deadline exceeded (raises), returning the first output URL.
text_to_video and image_to_video public methods
backend/director/tools/muapi_video.py
Each method builds its payload, resolves the muapi endpoint, calls _submit/_poll, downloads video bytes to save_at, and returns {"status": "success", "video_path": save_at}; exceptions are re-raised with type and message included.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant MuApiVideoGenerationTool
  participant muapi_ai as muapi.ai API

  Caller->>MuApiVideoGenerationTool: text_to_video(prompt, save_at, duration, config)
  MuApiVideoGenerationTool->>muapi_ai: POST generation request via _submit()
  muapi_ai-->>MuApiVideoGenerationTool: request_id
  loop _poll until completed or timeout
    MuApiVideoGenerationTool->>muapi_ai: GET prediction status
    muapi_ai-->>MuApiVideoGenerationTool: status + output URL
  end
  MuApiVideoGenerationTool->>muapi_ai: GET output URL
  muapi_ai-->>MuApiVideoGenerationTool: video bytes
  MuApiVideoGenerationTool-->>Caller: {"status": "success", "video_path": save_at}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop, hop, a tool takes flight,
Prompt to pixels, dark to light,
Polling softly, byte by byte,
Saving videos just right,
Muapi hums; the bunny beams 🎬

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a MuAPI video generation tool.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/director/tools/muapi_video.py`:
- Around line 123-127: The _submit method directly accesses
resp.json()["request_id"] which will raise a raw KeyError if the key is missing
from the API response. Wrap the resp.json()["request_id"] access in a try-except
block to catch KeyError, and when caught, raise a more informative exception
that includes the actual response content to aid debugging. This will provide
clear context about what the API returned instead of the expected request_id.
- Around line 162-172: The exception handling in the video generation code is
losing the original traceback by re-raising a new Exception without preserving
the exception chain. Modify the raise statement in the except block (where the
message "Error generating video" is constructed) to use the `from e` syntax to
preserve the original exception context. Apply the same fix to the
`image_to_video` method (mentioned at line 202) where this issue also exists.
This ensures the full traceback is retained for better debugging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fda5b229-148f-4b43-aa38-9f0d6164ad14

📥 Commits

Reviewing files that changed from the base of the PR and between 70e0b3d and 387afb0.

📒 Files selected for processing (1)
  • backend/director/tools/muapi_video.py

Comment thread backend/director/tools/muapi_video.py Outdated
Comment thread backend/director/tools/muapi_video.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/director/tools/muapi_video.py`:
- Around line 129-132: The _submit error handling in muapi_video.py currently
catches KeyError but loses the original exception context. Update the KeyError
handler in the _submit flow to bind the exception as a variable and re-raise the
new Exception with explicit chaining from that caught KeyError so the traceback
and source failure are preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bba1f1e4-06b4-4aab-8ea8-b65f62b0d6f3

📥 Commits

Reviewing files that changed from the base of the PR and between 387afb0 and 6e3aff4.

📒 Files selected for processing (1)
  • backend/director/tools/muapi_video.py

Comment thread backend/director/tools/muapi_video.py Outdated
raise ... from e preserves the original KeyError so callers get a
complete stack trace instead of losing context at the re-raise point
@Anil-matcha

Copy link
Copy Markdown
Author

Thanks for the review. Fixed exception chaining in _submit() in the latest push:

# Before
except KeyError:
    raise Exception(f"MuAPI did not return a request_id. Response: {resp.text}")

# After
except KeyError as e:
    raise Exception(f"MuAPI did not return a request_id. Response: {resp.text}") from e

The from e preserves the original KeyError in the traceback so callers see the full exception chain rather than losing context at the re-raise point.

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.

1 participant