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:

  1. Account & payment friction: Several leading video models (Kuaishou's Kling, ByteDance's Seedance 2.5, MiniMax's Hailuo H3, Alibaba's Wan 3.0 / HappyHorse 1.1) split domestic China and overseas endpoints, or require separate enterprise contracts, regional KYC, or distinct prepaid balances per vendor.
  2. Incompatible async schemas: One vendor expects POST /v1/video/generate with per-second billing, another prices by 1M video tokens (dreamina-seedance-2-5-260628), while Midjourney v8.2 renders 4-image grids asynchronously and encodes aspect ratios (--ar) and native 2K (--hd) inside the prompt string rather than JSON fields.
  3. Silent parameter drops & surprise bills: Passing an unsupported aspect ratio or legacy flag often gets silently ignored—or fails 90 seconds into rendering—making per-job unit economics hard to reconcile in multi-tenant SaaS apps.

In 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).

Architecture Overview: Two Submit Endpoints, One Polling Contract

Through an OpenAI/media-compatible gateway surface (https://api.hop-base.com/v1), all three model families share a clean two-step asynchronous lifecycle:

Model Family Exact Model IDs Submit Endpoint Poll Endpoint Output & Billing Unit (Official List Benchmark)
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)
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)
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)

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 (always check live vendor pages; enterprise account rates on HopBase are quoted per customer).

Step 0: Verify Your API Key's Model Scope First

Never 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:

export HOPBASE_API_KEY="sk-..." curl -sS https://api.hop-base.com/v1/models \ -H "Authorization: Bearer $HOPBASE_API_KEY" \ | jq -r '.data[].id | select(test("^(kling-v4|dreamina-seedance-2-5|midjourney-v8-2)"))' 

1. Calling Kling v4 (kling-v4): 3–30s Native-Audio Video

Three important kling-v4 contract details save hours of debugging:

  • Native sound is always included: kling-v4 generates synchronized audio even if audio: false is sent, and 720p ($0.1471/s list) / 1080p ($0.2206/s list) bill identically either way.
  • Duration range: Accepts integer seconds from 3 to 30.
  • First-frame image-to-video: Supports text-to-video and single first-frame image-to-video. When a first-frame image is supplied, output aspect ratio automatically follows the input image (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.
# Submit Kling v4 1080p 5-second video task curl -sS https://api.hop-base.com/v1/video/generate \ -H "Authorization: Bearer $HOPBASE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "kling-v4", "prompt": "Handheld tracking shot through a rain-soaked Tokyo alley at dusk, neon reflections on wet asphalt, footsteps and distant thunder", "duration": 5, "resolution": "1080p", "aspect_ratio": "16:9", "audio": true }' 

2. Calling Overseas Seedance 2.5 (dreamina-seedance-2-5-260628)

Overseas 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:

  • duration: Supports -1 (model-chosen optimal length) or integers 4–30. Video editing requires duration: -1 and ratio: "adaptive".
  • Reference media: Reference images/videos/audio on Seedance 2.5 must be public 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 720p list), while image-only references stay in the standard bucket.
  • 4K pricing nuance: 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.
curl -sS https://api.hop-base.com/v1/video/generate \ -H "Authorization: Bearer $HOPBASE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "dreamina-seedance-2-5-260628", "content": [ { "type": "text", "text": "Macro slow-motion espresso extraction into a warmed glass demitasse, golden crema swirling under warm morning sunlight" } ], "duration": 5, "resolution": "720p", "ratio": "16:9", "generate_audio": true, "watermark": false }' 

3. Calling Midjourney v8.2 (midjourney-v8-2): 4-Image Async Jobs & Prompt Flags

Unlike 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:

  • 4 images per call: Every completed job returns 4 signed URLs in outputs (valid for 24 hours; download and persist to your own S3/R2 bucket promptly).
  • Flags live in prompt, not JSON keys: Passing a top-level aspect_ratio field returns HTTP 400 (set the aspect ratio with --ar in the prompt). Append --ar 16:9 for widescreen (1456×816) and --hd for native 2K (2944×1648).
  • Fail-fast validation: Unsupported flags on v8.2 (--q, --niji, --cref, --oref, :: multi-prompt weights, or decimal ratios like --ar 1.5:1) are rejected synchronously at submit time with HTTP 400 and are never billed.
curl -sS https://api.hop-base.com/v1/images/generations \ -H "Authorization: Bearer $HOPBASE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "midjourney-v8-2", "prompt": "architectural cutaway of a minimalist cliffside library overlooking misty fjords, warm cedar interior --ar 16:9 --hd --s 250" }' 

Unified Production Python Client: Submit, Poll & Reconcile Exact USD Cost

Every 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:

import asyncio import os from typing import Any import httpx BASE_URL = "https://api.hop-base.com/v1" API_KEY = os.environ["HOPBASE_API_KEY"] async def run_media_task( client: httpx.AsyncClient, submit_path: str, payload: dict[str, Any], *, poll_interval_s: float = 4.0, timeout_s: float = 600.0, ) -> dict[str, Any]: headers = {"Authorization": f"Bearer {API_KEY}"} submit_resp = await client.post(f"{BASE_URL}{submit_path}", json=payload, headers=headers) submit_resp.raise_for_status() submitted = submit_resp.json() task_id = submitted.get("id") or submitted.get("task", {}).get("id") if not task_id: raise RuntimeError(f"Unexpected submit payload: {submitted}") loop = asyncio.get_running_loop() deadline = loop.time() + timeout_s while loop.time() < deadline: await asyncio.sleep(poll_interval_s) poll_resp = await client.get(f"{BASE_URL}/video/tasks/{task_id}", headers=headers) poll_resp.raise_for_status() task = poll_resp.json() status = task.get("status") if status == "completed": return { "task_id": task_id, "model": payload["model"], "outputs": task.get("outputs", []), "cost_usd": (task.get("usage") or {}).get("cost_usd", 0.0), } if status in ("failed", "cancelled"): cost_usd = (task.get("usage") or {}).get("cost_usd", 0.0) raise RuntimeError(f"Task {task_id} {status} (billed=${cost_usd}): {task.get('error')}") raise TimeoutError(f"Task {task_id} did not finish within {timeout_s}s") async def main() -> None: async with httpx.AsyncClient(timeout=30.0) as client: mj_job, kling_job, seedance_job = await asyncio.gather( run_media_task( client, "/images/generations", { "model": "midjourney-v8-2", "prompt": "editorial product photo of brushed titanium headphones on slate stone --ar 4:3 --hd", }, ), run_media_task( client, "/video/generate", { "model": "kling-v4", "prompt": "Slow orbital camera around brushed titanium headphones on slate stone, soft studio rim light", "duration": 5, "resolution": "1080p", "aspect_ratio": "16:9", }, ), run_media_task( client, "/video/generate", { "model": "dreamina-seedance-2-5-flash-261115", "content": [{"type": "text", "text": "Soundwave particles rippling outward in dark studio space"}], "duration": 5, "resolution": "720p", "ratio": "16:9", }, ), ) for res in (mj_job, kling_job, seedance_job): print(f"[{res['model']}] id={res['task_id']} cost_usd=${res['cost_usd']} outputs={len(res['outputs'])}") if __name__ == "__main__": asyncio.run(main()) 

Production Checklist Before Going Live

  1. Persist output media within 24 hours: Signed URLs in outputs expire 24 hours after completion (HTTP 410 afterward). Stream completed assets straight to S3, Cloudflare R2, or GCS in your worker.
  2. Scope one API key per tenant or environment: Attach only the groups your workflow needs (e.g., Kling + Seedance + Midjourney + Claude/GPT for prompt rewriting) and set a USD spend cap per key so a runaway loop cannot drain your balance.
  3. Inspect parameter limits from your IDE via MCP: Add https://api.hop-base.com/mcp (HopBase-AI/hopbase-mcp) to Claude Code or Cursor to query get_model_limits and list_models without leaving your editor.

Further Reading & Specs