DEV Community

rollingbottle
rollingbottle

Posted on Edited on AI-assisted

Calling Seedance, Kling, and Veo with One API Key: Clamping Model Limits in Node.js and Python

Disclosure: I'm on the Cuddler team and work on the Cuddler Platform API (https://platform.cuddler.ai) at HAKKO AI PTE. LTD. Cuddler's video studio is at https://cuddler.ai/studio. This post uses the API, so treat it as a vendor tutorial, not a neutral comparison.

Wiring Seedance, Kling, and Veo into one pipeline usually means three vendor accounts, three billing pages, three job schemas, and three sets of request fields. Putting them behind a single Cuddler Platform API key removes the account and polling boilerplate, but one integration snag stays: each model enforces its own duration bounds, aspect ratios, and optional fields, and sending an unsupported field fails immediately.

Below, the Node.js and Python examples fetch the live catalog, clamp your settings to each model's limits, estimate cost, and submit jobs with an Idempotency-Key. One caveat: I ran the keyless catalog lookup and payload builder in both languages against the live catalog, while the create and poll calls follow the official quickstart and were not run with a live key.

This uses the public docs (https://platform.cuddler.ai/docs) and model catalog (https://api.cuddler.ai/v1/catalog). On 2026-11-26 the catalog listed 64 entries, 63 enabled: 29 video, 22 image, 8 speech, and 4 music models.

Prerequisites and test-key limits

  • An organization and API key from the console (https://platform.cuddler.ai/console). Per the docs, there is no application or approval step.
  • Account balance for live jobs. A test key (cud_sk_test_…) needs no balance and works for reading the catalog, estimating prices, and checking your balance, though it cannot start a video.
  • Node.js 18+ (built-in fetch) or Python 3.10+ with requests.
export CUDDLER_API_KEY="cud_sk_live_..."   # keep it on the server
Enter fullscreen mode Exit fullscreen mode

Step 1: Query the catalog for each model's limits

The catalog is public and needs no key:

curl -s https://api.cuddler.ai/v1/catalog \
  | jq '.models[] | select(.id=="seedance-2.5" or .id=="kling-3.0" or .id=="veo-3.1")
        | {id, min_duration, max_duration, resolutions, aspect_ratios, native_audio, request_fields}'
Enter fullscreen mode Exit fullscreen mode

Snapshot read on 2026-11-26:

Model Duration Resolutions Aspect ratios Request fields beyond model, prompt, duration, resolution, aspect_ratio
seedance-2.5 4–30 s 480p, 720p, 1080p, 4K 16:9, 9:16, 4:3, 3:4, 1:1, 21:9, adaptive Seedance entries leave request_fields out; the docs list the Seedance fields separately
kling-3.0 3–30 s 720p, 1080p, 4K 16:9, 9:16, 1:1, adaptive first_frame, last_frame, reference_images, reference_videos, generate_audio, character_orientation
veo-3.1 4–8 s 720p, 1080p, 4K 16:9, 9:16 first_frame, generate_audio

The constraint that shapes your client code: POST /v1/videos rejects unknown fields with 400 invalid_request. A single catch-all payload breaks across models, so build each request from the model's catalog entry.

Step 2: Estimate job cost before spending

Pass the same model, duration, resolution, and aspect_ratio to the estimate endpoint before rendering. It never charges you, and a test key works:

curl https://api.cuddler.ai/v1/videos/estimate \
  -H "Authorization: Bearer $CUDDLER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"veo-3.1","duration":8,"resolution":"720p","aspect_ratio":"16:9"}'
Enter fullscreen mode Exit fullscreen mode

Seedance bills per token while the other models bill per second of output, so list rates are not directly comparable. Call the estimate endpoint with your real settings instead. Prices are omitted here because they change; read them from the estimate response.

Step 3: Clamp payloads and poll jobs in Node.js and Python

Both scripts fetch the catalog once, clamp duration, fall back to a supported resolution and aspect_ratio, and send generate_audio only when advertised. Every create call requires an Idempotency-Key: retrying after a timeout with the same key and body returns the original job instead of charging twice.

Node.js (ESM, saved as compare.mjs):

const API = "https://api.cuddler.ai/v1";
const headers = {
  Authorization: `Bearer ${process.env.CUDDLER_API_KEY}`,
  "Content-Type": "application/json",
};

// Public, no key: what each model accepts.
const catalog = await (await fetch(`${API}/catalog`)).json();
const byId = Object.fromEntries(catalog.models.map((m) => [m.id, m]));

function buildBody(modelId, prompt, wanted) {
  const m = byId[modelId];
  if (!m?.enabled) throw new Error(`${modelId} is not enabled`);
  const duration = Math.min(Math.max(wanted.duration, m.min_duration), m.max_duration);
  const resolution = m.resolutions.includes(wanted.resolution) ? wanted.resolution : m.resolutions[0];
  const aspect_ratio = m.aspect_ratios.includes(wanted.aspect_ratio) ? wanted.aspect_ratio : m.aspect_ratios[0];
  const body = { model: modelId, prompt, duration, resolution, aspect_ratio };
  // Only send generate_audio where the catalog says the model takes it
  // (Seedance entries have no request_fields, so check the docs for those).
  if (m.request_fields?.includes("generate_audio")) body.generate_audio = true;
  return body;
}

async function generate(body, idempotencyKey) {
  const res = await fetch(`${API}/videos`, {
    method: "POST",
    headers: { ...headers, "Idempotency-Key": idempotencyKey },
    body: JSON.stringify(body),
  });
  if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
  let video = await res.json();
  while (video.status === "queued" || video.status === "running") {
    await new Promise((r) => setTimeout(r, 15000));
    const poll = await fetch(`${API}/videos/${video.id}`, { headers });
    if (!poll.ok) throw new Error(`${poll.status} ${await poll.text()}`);
    video = await poll.json();
  }
  return video;
}

const prompt = "A paper boat drifts down a rain-filled street at dusk. Slow dolly in.";
const wanted = { duration: 8, resolution: "720p", aspect_ratio: "16:9" };

for (const modelId of ["seedance-2.5", "kling-3.0", "veo-3.1"]) {
  const body = buildBody(modelId, prompt, wanted);
  const video = await generate(body, `compare-${modelId}-take1`);
  console.log(modelId, video.status, video.output?.url ?? video.error);
}
Enter fullscreen mode Exit fullscreen mode

Python:

import os, time, requests

API = "https://api.cuddler.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['CUDDLER_API_KEY']}"}
catalog = requests.get(f"{API}/catalog", timeout=30).json()
by_id = {m["id"]: m for m in catalog["models"]}

def build_body(model_id, prompt, wanted):
    m = by_id[model_id]
    assert m["enabled"], f"{model_id} is not enabled"
    duration = min(max(wanted["duration"], m["min_duration"]), m["max_duration"])
    resolution = wanted["resolution"] if wanted["resolution"] in m["resolutions"] else m["resolutions"][0]
    aspect = wanted["aspect_ratio"] if wanted["aspect_ratio"] in m["aspect_ratios"] else m["aspect_ratios"][0]
    body = {"model": model_id, "prompt": prompt, "duration": duration,
            "resolution": resolution, "aspect_ratio": aspect}
    if "generate_audio" in (m.get("request_fields") or []):
        body["generate_audio"] = True
    return body

def generate(body, key):
    r = requests.post(f"{API}/videos", json=body,
                      headers={**HEADERS, "Idempotency-Key": key}, timeout=60)
    r.raise_for_status()
    video = r.json()
    while video["status"] in ("queued", "running"):
        time.sleep(15)
        video = requests.get(f"{API}/videos/{video['id']}", headers=HEADERS, timeout=30).json()
    return video

prompt = "A paper boat drifts down a rain-filled street at dusk. Slow dolly in."
for model_id in ("seedance-2.5", "kling-3.0", "veo-3.1"):
    v = generate(build_body(model_id, prompt, {"duration": 8, "resolution": "720p", "aspect_ratio": "16:9"}),
                 f"compare-{model_id}-take1")
    print(model_id, v["status"], (v.get("output") or {}).get("url") or v.get("error"))
Enter fullscreen mode Exit fullscreen mode

When status hits succeeded, output.url is a signed download link valid for one hour. Fetch the video again if it expires; the file stays stored for 30 days.

Production gotchas: idempotency, rate limits, and model retirement

  • Idempotency is mandatory. A missing Idempotency-Key returns 400; reusing a key with a different body returns 409. Use one key per logical request.
  • Polling vs. webhooks. Polling every 15 seconds stays well inside the read cap (300 reads per minute per key). At higher volume, pass webhook_url and verify the Cuddler-Signature header instead.
  • Default concurrency is tight. A new organization renders 2 videos at once and queues up to 20 more, rising with top-ups (docs: https://platform.cuddler.ai/docs/limits.md). Writes cap at 60 per minute per key.
  • Expect model retirements. Retired upstream models return 410 model_retired. Reading the catalog at startup avoids failing on hard-coded IDs.
  • Not OpenAI-compatible. This is a native API with its own job objects. If your stack requires an OpenAI-shaped endpoint, pick another tool.
  • Agent / MCP access. The same API runs as a remote MCP server (https://api.cuddler.ai/v1/mcp, Bearer key). A test key only exposes the 8 read and estimate tools, so an agent holding one cannot spend.

Price check: Seedance rates against fal and Runway (read 2026-11-26)

If you are choosing where to run Seedance, here are the rows where Cuddler's published rate is at least 5% below another provider's published rate. All rows are the same spec: text-to-video, audio on, 16:9, no video input. I read each provider's public pricing page on 2026-11-26; prices change, so check them before you commit. This is a comparison against fal and Runway only, not a ranking of the market.

Against fal (USD, per 1M tokens and per second; per-second figures use the same token count for both sides):

Model Resolution Cuddler $/1M tokens fal $/1M tokens Cuddler $/s fal $/s Cuddler lower by Lower by with 5.5% card fee
Seedance 2.5 480p $16.05 $21.40 $0.155 $0.206 25% 20%
Seedance 2.5 720p $16.05 $21.40 $0.348 $0.464 25% 20%
Seedance 2.5 1080p $17.55 $23.40 $0.857 $1.142 25% 20%
Seedance 2.0 480p $10.50 $14.00 $0.106 $0.141 25% 20%
Seedance 2.0 720p $10.50 $14.00 $0.228 $0.304 25% 20%
Seedance 2.0 1080p $11.55 $14.00 $0.564 $0.683 17% 12%
Seedance 2.5 Flash 480p $10.50 $14.00 $0.101 $0.135 25% 20%
Seedance 2.5 Flash 720p $10.50 $14.00 $0.228 $0.304 25% 20%

Against Runway's API (USD per second, as listed on Runway's pricing page at $0.01 per credit):

Model Resolution Cuddler $/s Runway $/s Cuddler lower by Lower by with 5.5% card fee
Seedance 2.5 480p $0.155 $0.20 22% 18%
Seedance 2.5 Flash 480p $0.101 $0.13 22% 17%
Seedance 2.0 480p $0.106 $0.14 24% 20%
Seedance 2.0 720p $0.228 $0.30 24% 19%

How to read it: Cuddler's list prices above exclude the 5.5% processing fee on online card top-ups, so the last column adds it to Cuddler's side (percentages are rounded down). The fal and Runway figures are as published, with no taxes or fees added. Runway's page does not state a separate audio charge, so I compared its listed rate directly. Volume discounts, credits, and promotions on either side are not included.

On promotions: through December 4 (UTC), the Cuddler Platform Black Friday offer matches a first top-up up to $50 for the first 200 organizations and waives the online top-up card fee up to $2,000 per organization. Model prices stay the same, so the table above is unchanged by it.

Current Cuddler rates are on https://platform.cuddler.ai/pricing.

Next step: test your request builder without spending

Verify your payload logic before funding an account: run the curl catalog query above for the models you need, grab a free test key from the console to price your target durations and resolutions through the estimate endpoint, and wire up buildBody (or build_body) before switching to a live key.

Reference links

Top comments (0)