{"slug": "calling-kling-v4-seedance-2-5-midjourney-v8-2-outside-china-with-one-unified-api", "title": "Calling Kling v4, Seedance 2.5 & Midjourney v8.2 Outside China with One Unified Async API", "summary": "A developer published an engineering walkthrough showing how to integrate Kling v4, ByteDance Seedance 2.5, and Midjourney v8.2 into a single Python asyncio client through an OpenAI/media-compatible gateway at api.hop-base.com. The client uses one API key, a shared two-step submit-and-poll lifecycle, startup validation of model IDs via GET /v1/models, and per-task USD cost reconciliation through usage.cost_usd. The writeup details model-specific contracts, including Kling's 3–30s clips with native audio, Seedance's structured content segments and per-token billing, and Midjourney's four-image jobs with prompt-string parameters.", "body_md": "If you are building a creative studio, ad-tech generator, storyboard tool, or multimodal AI agent outside China, integrating the top video and image generation models usually turns into an infrastructure headache:\n\n`POST /v1/video/generate` with per-second billing, another prices by 1M video tokens (`dreamina-seedance-2-5-260628`), while `--ar`) and native 2K (`--hd`) inside the prompt string rather than JSON fields.\nIn this engineering walkthrough, we will wire **Kling v4 (`kling-v4`)**, **ByteDance Seedance 2.5 (` dreamina-seedance-2-5-260628`)**, and **Midjourney v8.2 (` midjourney-v8-2`)** into a single Python `asyncio` client with **one API key, one polling loop, strict submit-time validation, and exact per-task USD cost reconciliation (`usage.cost_usd`)**.\n\nThrough an OpenAI/media-compatible gateway surface (`https://api.hop-base.com/v1`), all three model families share a clean two-step asynchronous lifecycle:\n\n| Model Family | Exact Model IDs | Submit Endpoint | Poll Endpoint | Output & Billing Unit (Official List Benchmark) | \n|---|---|---|---|---|\n| **Kuaishou Kling 4.0** | `kling-v4` ,`kling-v4-flash` | `POST /v1/video/generate` | `GET /v1/video/tasks/{id}` | 3–30s clip ( `720p``$0.1471/s` ,`1080p``$0.2206/s` w/ native audio; Flash`720p``$0.08824/s` ) | \n| **ByteDance Seedance 2.5** | `dreamina-seedance-2-5-260628` ,`dreamina-seedance-2-5-flash-261115` | `POST /v1/video/generate` | `GET /v1/video/tasks/{id}` | 4–30s (or `-1` auto) clip,`480p` –`4k` (`$10.70/1M` video tok at`720p` no-ref; Flash`$7.00/1M` ) | \n| **Midjourney v8.2** | `midjourney-v8-2` | `POST /v1/images/generations` (`202` ) | `GET /v1/video/tasks/{id}` | 4 candidate images per job ( `1K``$0.0441/img` =`$0.1765/job` ;`--hd`` 2K``$0.0559/img` =`$0.2235/job` ) | \n\n*Note on pricing & ownership: Kling is a Kuaishou product, Seedance is a ByteDance product, and Midjourney is a Midjourney product. All prices cited above are published official vendor list price benchmarks in USD from [HopBase-AI/llm-api-pricing](https://github.com/HopBase-AI/llm-api-pricing) (always check live vendor pages; enterprise account rates on [HopBase](https://hop-base.com/pricing) are quoted per customer).*\n\nNever hardcode or guess model suffixes. Every API key is scoped to the model groups attached to it in the console—always query `GET /v1/models` at startup to confirm the exact IDs available to your key:\n\n```\nexport HOPBASE_API_KEY=\"sk-...\"\n\ncurl -sS https://api.hop-base.com/v1/models \\\n  -H \"Authorization: Bearer $HOPBASE_API_KEY\" \\\n  | jq -r '.data[].id | select(test(\"^(kling-v4|dreamina-seedance-2-5|midjourney-v8-2)\"))'\n```\n\n`kling-v4`): 3–30s Native-Audio Video\nThree important `kling-v4` contract details save hours of debugging:\n\n`audio: false` is sent, and `720p` (`$0.1471/s` list) / `1080p` (`$0.2206/s` list) bill identically either way.`3` to `30`.` aspect_ratio` is ignored). For multi-shot storyboards (`shots` with up to 6 segments) or character motion transfer, use `kling-v3` / `kling-v3-omni` or `kling-v3-motion-control`.\n\n```\n# Submit Kling v4 1080p 5-second video task\ncurl -sS https://api.hop-base.com/v1/video/generate \\\n  -H \"Authorization: Bearer $HOPBASE_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"kling-v4\",\n    \"prompt\": \"Handheld tracking shot through a rain-soaked Tokyo alley at dusk, neon reflections on wet asphalt, footsteps and distant thunder\",\n    \"duration\": 5,\n    \"resolution\": \"1080p\",\n    \"aspect_ratio\": \"16:9\",\n    \"audio\": true\n  }'\n```\n\nOverseas Seedance 2.5 (`dreamina-seedance-2-5-260628`) and its high-speed sibling Seedance 2.5 Flash (` dreamina-seedance-2-5-flash-261115`, `480p`/` 720p`) use structured `content` segments:\n\n`duration`:`-1` (model-chosen optimal length) or integers `4`–` duration: -1` and `ratio: \"adaptive\"`.` https://` URLs. Note that video input switches billing into the lower per-token reference bucket (`$6.40` vs `$10.70` per 1M video tokens at `4k`, the per-million-token rate is `$4.70` (no video ref) / `$2.90` (with video ref) because a 4K frame contains 4x the tokens of a 1080p frame.\n\n```\ncurl -sS https://api.hop-base.com/v1/video/generate \\\n  -H \"Authorization: Bearer $HOPBASE_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"dreamina-seedance-2-5-260628\",\n    \"content\": [\n      {\n        \"type\": \"text\",\n        \"text\": \"Macro slow-motion espresso extraction into a warmed glass demitasse, golden crema swirling under warm morning sunlight\"\n      }\n    ],\n    \"duration\": 5,\n    \"resolution\": \"720p\",\n    \"ratio\": \"16:9\",\n    \"generate_audio\": true,\n    \"watermark\": false\n  }'\n```\n\n`midjourney-v8-2`): 4-Image Async Jobs & Prompt Flags\nUnlike single-image synchronous endpoints, `midjourney-v8-2` submits via `POST /v1/images/generations` (returning HTTP `202` + task `id`) and polls on the **exact same** `GET /v1/video/tasks/{task_id}` endpoint:\n\n`outputs` (valid for 24 hours; download and persist to your own S3/R2 bucket promptly).`prompt`, not JSON keys:` HTTP 400` (`set the aspect ratio with --ar in the prompt`). Append `--ar 16:9` for widescreen (`1456×816`) and `2944×1648`).`--q`, `--niji`, `--cref`, `--oref`, `::` multi-prompt weights, or decimal ratios like `--ar 1.5:1`) are rejected synchronously at submit time with \n\n```\ncurl -sS https://api.hop-base.com/v1/images/generations \\\n  -H \"Authorization: Bearer $HOPBASE_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"midjourney-v8-2\",\n    \"prompt\": \"architectural cutaway of a minimalist cliffside library overlooking misty fjords, warm cedar interior --ar 16:9 --hd --s 250\"\n  }'\n```\n\nEvery terminal task response (`completed`, `failed`, or `cancelled`) from `GET /v1/video/tasks/{task_id}` includes a top-level `usage` object with `cost_usd`—the exact USD amount deducted for that job (` 0` if rejected or timed out). That means your multi-tenant SaaS backend can record exact per-job COGS without estimating video tokens:\n\n``` python\nimport asyncio\nimport os\nfrom typing import Any\nimport httpx\n\nBASE_URL = \"https://api.hop-base.com/v1\"\nAPI_KEY = os.environ[\"HOPBASE_API_KEY\"]\n\nasync def run_media_task(\n    client: httpx.AsyncClient,\n    submit_path: str,\n    payload: dict[str, Any],\n    *,\n    poll_interval_s: float = 4.0,\n    timeout_s: float = 600.0,\n) -> dict[str, Any]:\n    headers = {\"Authorization\": f\"Bearer {API_KEY}\"}\n    submit_resp = await client.post(f\"{BASE_URL}{submit_path}\", json=payload, headers=headers)\n    submit_resp.raise_for_status()\n    submitted = submit_resp.json()\n\n    task_id = submitted.get(\"id\") or submitted.get(\"task\", {}).get(\"id\")\n    if not task_id:\n        raise RuntimeError(f\"Unexpected submit payload: {submitted}\")\n\n    loop = asyncio.get_running_loop()\n    deadline = loop.time() + timeout_s\n    while loop.time() < deadline:\n        await asyncio.sleep(poll_interval_s)\n        poll_resp = await client.get(f\"{BASE_URL}/video/tasks/{task_id}\", headers=headers)\n        poll_resp.raise_for_status()\n        task = poll_resp.json()\n        status = task.get(\"status\")\n        if status == \"completed\":\n            return {\n                \"task_id\": task_id,\n                \"model\": payload[\"model\"],\n                \"outputs\": task.get(\"outputs\", []),\n                \"cost_usd\": (task.get(\"usage\") or {}).get(\"cost_usd\", 0.0),\n            }\n        if status in (\"failed\", \"cancelled\"):\n            cost_usd = (task.get(\"usage\") or {}).get(\"cost_usd\", 0.0)\n            raise RuntimeError(f\"Task {task_id} {status} (billed=${cost_usd}): {task.get('error')}\")\n\n    raise TimeoutError(f\"Task {task_id} did not finish within {timeout_s}s\")\n\nasync def main() -> None:\n    async with httpx.AsyncClient(timeout=30.0) as client:\n        mj_job, kling_job, seedance_job = await asyncio.gather(\n            run_media_task(\n                client,\n                \"/images/generations\",\n                {\n                    \"model\": \"midjourney-v8-2\",\n                    \"prompt\": \"editorial product photo of brushed titanium headphones on slate stone --ar 4:3 --hd\",\n                },\n            ),\n            run_media_task(\n                client,\n                \"/video/generate\",\n                {\n                    \"model\": \"kling-v4\",\n                    \"prompt\": \"Slow orbital camera around brushed titanium headphones on slate stone, soft studio rim light\",\n                    \"duration\": 5,\n                    \"resolution\": \"1080p\",\n                    \"aspect_ratio\": \"16:9\",\n                },\n            ),\n            run_media_task(\n                client,\n                \"/video/generate\",\n                {\n                    \"model\": \"dreamina-seedance-2-5-flash-261115\",\n                    \"content\": [{\"type\": \"text\", \"text\": \"Soundwave particles rippling outward in dark studio space\"}],\n                    \"duration\": 5,\n                    \"resolution\": \"720p\",\n                    \"ratio\": \"16:9\",\n                },\n            ),\n        )\n\n        for res in (mj_job, kling_job, seedance_job):\n            print(f\"[{res['model']}] id={res['task_id']} cost_usd=${res['cost_usd']} outputs={len(res['outputs'])}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n`HTTP 410` afterward). Stream completed assets straight to S3, Cloudflare R2, or GCS in your worker.`https://api.hop-base.com/mcp` (`get_model_limits` and `list_models` without leaving your editor.", "url": "https://wpnews.pro/news/calling-kling-v4-seedance-2-5-midjourney-v8-2-outside-china-with-one-unified-api", "canonical_source": "https://dev.to/hopbase/calling-kling-v4-seedance-25-midjourney-v82-outside-china-with-one-unified-async-api-lgf", "published_at": "2026-12-04 03:42:10+00:00", "updated_at": "2026-12-04 03:45:48.607557+00:00", "lang": "en", "topics": ["ai-products", "generative-ai", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Kling", "Kuaishou", "Seedance", "ByteDance", "Midjourney", "HopBase", "api.hop-base.com"], "also_reported_by": [], "takeaway": "Route Kling v4, Seedance 2.5 and Midjourney v8.2 through one OpenAI-compatible gateway with a shared submit-then-poll loop, validate exact model IDs via GET /v1/models at startup, and reconcile spend per task with usage.cost_usd.", "recommendation": {"advice": "Query GET /v1/models at startup instead of hardcoding model suffixes, since each API key is scoped to specific model groups, and track usage.cost_usd per task to reconcile spend across providers.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/calling-kling-v4-seedance-2-5-midjourney-v8-2-outside-china-with-one-unified-api", "markdown": "https://wpnews.pro/news/calling-kling-v4-seedance-2-5-midjourney-v8-2-outside-china-with-one-unified-api.md", "text": "https://wpnews.pro/news/calling-kling-v4-seedance-2-5-midjourney-v8-2-outside-china-with-one-unified-api.txt", "jsonld": "https://wpnews.pro/news/calling-kling-v4-seedance-2-5-midjourney-v8-2-outside-china-with-one-unified-api.jsonld"}}