{"record":{"id":"9109eb212438e321","repo":"ATH-MaaS/Pixelle-Video","slug":"api-media-service-is-not-initialized","errorCode":null,"errorMessage":"API media service is not initialized","messagePattern":"API media service is not initialized","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/media.py","lineNumber":210,"sourceCode":"                seed=42\n            )\n            \n            # With absolute path\n            media = await pixelle_video.media(\n                prompt=\"a cat\",\n                workflow=\"/path/to/custom.json\"\n            )\n            \n            # With custom ComfyUI server\n            media = await pixelle_video.media(\n                prompt=\"a cat\",\n                comfyui_url=\"http://192.168.1.100:8188\"\n            )\n        \"\"\"\n        selected_workflow = workflow or self.config.get(\"default_workflow\")\n        if selected_workflow and selected_workflow.startswith(\"api/\"):\n            if not self.core or not getattr(self.core, \"api_media\", None):\n                raise RuntimeError(\"API media service is not initialized\")\n            return await self.core.api_media(\n                prompt=prompt,\n                workflow=selected_workflow,\n                media_type=media_type,\n                width=width,\n                height=height,\n                duration=duration,\n                output_path=output_path,\n                image_path=image_path,\n                negative_prompt=negative_prompt,\n                steps=steps,\n                seed=seed,\n                cfg=cfg,\n                sampler=sampler,\n                **params\n            )\n\n        # 1. Resolve workflow (returns structured info)","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/media.py#L192-L228","documentation":"MediaService.__call__ routes any workflow starting with \"api/\" to a remote API media path via self.core.api_media. If the core object is missing or has no api_media attribute (the API media service was never initialized during setup), it raises RuntimeError instead of silently mis-dispatching.","triggerScenarios":"Calling pixelle_video.media(workflow='api/xxx.json', ...) (or a default_workflow config value beginning with 'api/') when the client was constructed without the API backend — e.g. initialized for selfhost ComfyUI only, so core or core.api_media is absent.","commonSituations":"Config file switched to api/ workflows but the client was built with selfhost-only initialization; environment variable selecting backend not set, so core.api_media never registered; reusing a partially constructed client after init failure.","solutions":["Initialize the client with the API backend enabled so core.api_media is registered (provide API credentials/config at construction)","Remove the 'api/' prefix from the workflow name if you intend to run the local/selfhost path","Check the config/default_workflow value and change it to a local workflow file","Log the initialization path and verify self.core is set and has api_media before dispatch"],"exampleFix":"// before\npv = PixelleVideo(config={...})  # API backend not configured\nawait pv.media(prompt=\"a cat\", workflow=\"api/video.json\")  # RuntimeError\n// after\npv = PixelleVideo(config={..., \"api_enabled\": True, \"api_key\": os.environ[\"PIXELLE_API_KEY\"]})\nassert pv.core and getattr(pv.core, \"api_media\", None), \"API backend missing\"\nawait pv.media(prompt=\"a cat\", workflow=\"api/video.json\")","handlingStrategy":"validation","validationCode":"def api_backend_ready(client) -> bool:\n    core = getattr(client, \"core\", None)\n    return core is not None and getattr(core, \"api_media\", None) is not None","typeGuard":"def has_api_media(core) -> bool:\n    return core is not None and callable(getattr(core, \"api_media\", None))","tryCatchPattern":"try:\n    media = await pv.media(prompt=p, workflow=wf)\nexcept RuntimeError as e:\n    if \"not initialized\" in str(e):\n        logger.error(\"API backend not configured; falling back to local workflow\")\n        media = await pv.media(prompt=p, workflow=\"image_flux.json\")\n    else:\n        raise","preventionTips":["Call api_backend_ready(client) at startup, before any media calls","Keep backend selection (selfhost vs api) and workflow prefixes consistent in one config place","Ensure required API env vars/keys are set before constructing the client","Fail fast at boot with a clear message instead of deep in a request path"],"tags":["python","initialization","configuration","runtime-error"],"backgroundTag":"service-not-initialized","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}