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:
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.
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).
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; Flash720p``$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 at720p 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).
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)"))'
kling-v4): 3–30s Native-Audio Video
Three important kling-v4 contract details save hours of debugging:
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.
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
}'
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:-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.
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
}'
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:
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
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"
}'
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())
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.