Skip to content

davepoon/buildwithclaude / plugins/all-skills/skills/muapi-media

muapi-media

Verified

Discover current MuAPI image models and run one explicitly confirmed asynchronous image generation request with bounded polling. Use when an agent needs hosted image generation without hard-coding stale model endpoints or request IDs.

FileKindSize
SKILL.mdskill md3.8 KB
scripts/muapi_media.pyscript11.2 KB
tests/test_muapi_media.pyscript3.3 KB

tests/test_muapi_media.py

View on GitHub
import sys
import unittest
from pathlib import Path
from unittest.mock import patch

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))

from muapi_media import MuAPIClient, MuAPIError


class MuAPIMediaTests(unittest.TestCase):
    def setUp(self):
        self.client = MuAPIClient(api_key="test-key")
        self.calls = []

    def test_models_reads_top_level_models_and_filters_image_categories(self):
        self.client._request = lambda method, path, **kwargs: {
            "models": [
                {"name": "flux-dev", "category": "Text to Image", "endpoint": "/api/v1/flux-dev"},
                {"name": "kling", "category": "Text to Video", "endpoint": "/api/v1/kling"},
            ],
            "total": 2,
        }

        models = self.client.models()

        self.assertEqual([model.name for model in models], ["flux-dev"])
        self.assertEqual(models[0].endpoint, "/api/v1/flux-dev")

    def test_generate_uses_catalog_endpoint_once_and_polls_get(self):
        responses = iter([
            {"models": [{"name": "flux-dev", "category": "Text to Image", "endpoint": "/api/v1/flux-dev"}]},
            {"request_id": "request-123", "status": "queued"},
            {"status": "processing"},
            {"status": "completed", "outputs": ["https://cdn.example/image.png"]},
        ])

        def fake_request(method, path, body=None, requires_auth=False):
            self.calls.append((method, path, body, requires_auth))
            return next(responses)

        self.client._request = fake_request
        with patch("muapi_media.time.sleep"):
            result = self.client.generate(
                "flux-dev",
                {"prompt": "a blue square"},
                confirm_paid=True,
                max_polls=3,
                poll_interval=0,
            )

        self.assertEqual(result["request_id"], "request-123")
        self.assertEqual(self.calls[1], ("POST", "/api/v1/flux-dev", {"prompt": "a blue square"}, True))
        self.assertEqual(self.calls[2][1], "/api/v1/predictions/request-123/result")
        self.assertEqual(self.calls[3][0], "GET")

    def test_generation_requires_paid_confirmation(self):
        with self.assertRaisesRegex(MuAPIError, "confirm-paid"):
            self.client.generate("flux-dev", {"prompt": "test"})

    def test_generation_requires_a_prompt(self):
        with self.assertRaisesRegex(MuAPIError, "non-empty string `prompt`"):
            self.client.generate("flux-dev", {}, confirm_paid=True)

    def test_endpoint_identifier_is_supported_without_double_prefix(self):
        self.client._request = lambda method, path, body=None, **kwargs: (
            {"models": [{"name": "flux-dev", "category": "Text to Image", "endpoint": "/api/v1/flux-dev"}]}
            if path == "/api/v1/models"
            else {"request_id": "request-123"}
            if method == "POST"
            else {"status": "completed", "outputs": ["https://cdn.example/image.png"]}
        )
        with patch("muapi_media.time.sleep"):
            result = self.client.generate(
                "/api/v1/flux-dev",
                {"prompt": "test"},
                confirm_paid=True,
                poll_interval=0,
            )
        self.assertEqual(result["endpoint"], "/api/v1/flux-dev")


if __name__ == "__main__":
    unittest.main()
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall