Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add MuAPI video generation tool#196

Open
Anil-matcha wants to merge 2 commits into
video-db:main from
Anil-matcha:feat/muapi-video-tool
Open

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

Conversation

@Anil-matcha

@Anil-matcha Anil-matcha commented Jun 17, 2026
edited by coderabbitai Bot
Loading

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, with configurable duration and aspect ratio options.
    • Added video generation from image URLs, including optional prompt-based guidance.
    • Integrated support for multiple underlying video generation models via model-specific endpoints (with automatic fallback for image-based models).

coderabbitai Bot commented Jun 17, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 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 accurately summarizes the main change: adding a new 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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

i️ 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

i️ 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 on lines +129 to +132
except KeyError:
raise Exception(
f"MuAPI did not return a request_id. Response: {resp.text}"
)

@coderabbitai coderabbitai Bot Jun 24, 2026

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.

📐 Maintainability & Code Quality | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Locate and inspect the target file around the referenced lines.
git ls-files backend/director/tools/muapi_video.py
wc -l backend/director/tools/muapi_video.py
sed -n '110,230p' backend/director/tools/muapi_video.py

Repository: video-db/Director

Length of output: 4157


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Check for any surrounding handling patterns in the file for KeyError chaining.
rg -n "except KeyError|raise .* from e|request_id|str\\(e\\)" backend/director/tools/muapi_video.py

Repository: video-db/Director

Length of output: 990


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Lightweight behavioral probe: confirm Python exception chaining semantics for the exact pattern.
python3 - <<'PY'
try:
 try:
 raise KeyError("x")
 except KeyError as e:
 raise Exception("wrapped") from e
except Exception as exc:
 print(type(exc).__name__)
 print(type(exc.__cause__).__name__ if exc.__cause__ else None)
PY

Repository: video-db/Director

Length of output: 174


Preserve the KeyError chain

_submit wraps the KeyError but drops the original traceback. Bind the exception and re-raise with from e so the source failure is preserved.

Proposed fix
- except KeyError:
+ except KeyError as e:
 raise Exception(
 f"MuAPI did not return a request_id. Response: {resp.text}"
- )
+ ) from e
📝 Committable suggestion

!!️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except KeyError:
raise Exception(
f"MuAPI did not return a request_id. Response: {resp.text}"
)
except KeyErrorase:
raise Exception(
f"MuAPI did not return a request_id. Response: {resp.text}"
)frome
🧰 Tools
🪛 Ruff (0.15.18)

[warning] 130-132: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

🤖 Prompt for 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.
In `@backend/director/tools/muapi_video.py` around lines 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.

Source: Linters/SAST tools

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

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /