---
name: media-hub
description: >-
Generate or edit images and videos across multiple third-party, gateway, and
custom AI media APIs configured in providers.yaml. Use when the user asks to
generate or edit images, generate or extend videos, route a media task to a
specific vendor/model, inspect async media jobs, or register and test new
media APIs.
---
# Media Hub
Unified multi-provider skill for image and video generation across OpenAI-compatible gateways, chat-based image models, asynchronous REST video/image endpoints, local/OAuth CLI bridges (`cli_bridge`), and custom Python adapters.
## File Layout
- `providers.yaml` — Built-in provider registry (deep-merged with `~/.media-hub/providers.yaml` and `<cwd>/.media-hub/providers.yaml`). Never put real API keys in YAML.
- `.env` — Local secrets only (loaded from `~/.media-hub/.env`, `<skill_dir>/.env`, `<cwd>/.media-hub/.env`, and process env). **Never ask the user to paste an API key into chat**; instruct them to edit `~/.media-hub/.env`.
- `references/custom-adapters.md` — Full schema for protocols, headers, templates, and custom adapters.
- `references/provider-templates.yaml` — Copy-pasteable templates for OpenAI, OpenRouter Gemini, SiliconFlow, Volcengine Ark / Seedream, and Fal.ai.
- `scripts/media_cli.py` — Unified Python CLI entrypoint next to this `SKILL.md`. Always invoke it by its absolute path while keeping CWD in the user's workspace so outputs save to `./outputs/media-hub/<YYYYMMDD>/` unless `--out` is passed.
## Quick Reference
Let `<CLI>` be the path to `scripts/media_cli.py` alongside this `SKILL.md`.
| Goal | Command |
|---|---|
| First-time setup (`~/.media-hub/.env` + `providers.yaml`) | `python "<CLI>" init --json` |
| Inspect ready providers | `python "<CLI>" list --ready --json` |
| Diagnose missing keys / config layers | `python "<CLI>" doctor --json` |
| Inspect one provider's defaults & endpoints | `python "<CLI>" show --provider <id> --json` |
| Preview request without spending credits | `python "<CLI>" generate --provider <id> --prompt "..." --dry-run --json` |
| Generate image (auto or explicit provider) | `python "<CLI>" generate [--provider <id>] --prompt "..." [--size 1024x1024] [--ar 16:9] --json` |
| Generate from long prompt file(s) | `python "<CLI>" generate [--provider <id>] --prompt-file ./style.md --prompt-file ./scene.md --out ./out.png --json` |
| Concurrent batch from JSON/YAML manifest | `python "<CLI>" batch --manifest ./jobs.yaml [--concurrency 3] [--dry-run] --json` |
| Edit / combine with reference image(s) | `python "<CLI>" generate --provider <id> --prompt "..." --image ./a.png [--image ./b.png] [--mask ./mask.png] --json` |
| Generate video (text or first/last frame) | `python "<CLI>" generate --provider <id> --prompt "..." [--first-frame ./f1.png] [--last-frame ./f2.png] [--duration 5] [--aspect-ratio 16:9] --json` |
| Pass vendor-specific extra parameters | `python "<CLI>" generate --provider <id> --prompt "..." -P seed=42 -P input.cfg=7.5 --json` |
| Check recent async tasks / recover `task_id` | `python "<CLI>" history --limit 10 --json` |
<!-- ‹guest · 2026-12-04› -->
| Check or resume an async task (`--provider` optional if in history) | `python "<CLI>" status --task-id <id> --json` / `wait --task-id <id> --json` |
## Workflow
1. **Discover configured providers first (never invent provider IDs or guess readiness):**
```bash
python "<CLI>" list --ready --json
```
If nothing is ready, run `doctor --json` and tell the user which env vars to set in `~/.media-hub/.env` (or which templates from `references/provider-templates.yaml` to copy into `~/.media-hub/providers.yaml`).
2. **Select provider & confirm costly options:**
- If the user named a provider or model, **always honor it** — never silently switch a user-named provider/model.
- Otherwise, match the task (`image` vs. `video`, `t2i`/`i2i`/`t2v`/`i2v`, draft vs. final, text rendering, photorealism) against each ready provider's `type`, `capabilities`, `priority`, and `best_for` (or pass `--provider auto`).
- For video jobs, multi-output batches, or newly added providers, run `--dry-run --json` first to verify the resolved URL/payload, and confirm provider, duration, and resolution with the user if ambiguous.
3. **Execute generation or editing:**
- For long/multi-line prompts or multi-image projects (covers, articles, slides, comics), write prompts to `.md` files first and pass repeatable `--prompt-file` (or use `batch --manifest ./jobs.yaml --concurrency 3`).
- Passing `--aspect-ratio` / `--ar` (e.g. `16:9`, `3:4`) without `--size` automatically maps to a valid pixel `size` on `openai_images` providers (customizable via `aspect_ratio_sizes`).
- Use repeatable `--image` for multi-reference edits and `--mask` for inpainting.
- Use `--out` for an explicit directory, file path, or template such as `./out/{index}{ext}`.
- Use `-P key=value` (repeatable; supports dot keys, JSON literals, and `@./local_file.png`) for provider-specific options not covered by standard flags.
4. **Async safety & exit codes (prevent duplicate paid billing):**
- `media_cli.py` uses semantic exit codes:
- `0` — completed, submitted (`--no-wait`), or `dry_run`.
- `1` — error (invalid config, API failure, remote task failed).
- `2` — **still running** (client poll timeout; NOT a failure).
- Every `async_rest` submission is immediately recorded in `~/.media-hub/history.jsonl` (path also shown by `doctor --json`).
- If a run exits with code `2`, is interrupted, or fails on a gateway/network error (`502/503/504`/timeout), **never immediately re-run `generate`**:
1. Run `python "<CLI>" history --limit 10 --json` to find the `task_id`.
2. Resume with `python "<CLI>" wait --provider <id> --task-id <task_id> --json` (or inspect once with `status`).
3. Only re-submit once if you have verified no matching task was created.
5. **Return results:**
- Report the saved file paths, provider and model used, and `task_id` (if async) from the JSON output.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.