gitroomhq/postiz-app · error · Error

Failed to generate video

Error message

Failed to generate video

What it means

The veo3 video generation integration calls kie.ai's create-task endpoint; if the response code is neither 200 nor 201 it throws the API's msg or the generic 'Failed to generate video'. This typically reflects an upstream API error: invalid API key, quota exhaustion, bad prompt/parameters, or provider-side failure.

Source

Thrown at libraries/nestjs-libraries/src/videos/veo3/veo3.ts:62

    const value = await (
      await fetch('https://api.kie.ai/api/v1/veo/generate', {
        headers: {
          'Content-Type': 'application/json',
          Authorization: `Bearer ${process.env.KIEAI_API_KEY}`,
        },
        method: 'POST',
        signal: AbortSignal.timeout(30000),
        body: JSON.stringify({
          prompt: customParams.prompt,
          imageUrls: customParams?.images?.map((p) => p.path) || [],
          model: 'veo3_fast',
          aspectRatio: output === 'horizontal' ? '16:9' : '9:16',
        }),
      })
    ).json();

    if (value.code !== 200 && value.code !== 201) {
      throw new Error(value?.msg || `Failed to generate video`);
    }

    const taskId = value.data.taskId;
    console.log('veo3 taskId', taskId);
    let attempts = 0;
    const maxAttempts = 180; // ~30 minutes at 10s interval
    while (true) {
      if (attempts++ >= maxAttempts) {
        throw new Error('Video generation timed out');
      }

      console.log('waiting for video to be ready');
      const data = await (
        await fetch(
          'https://api.kie.ai/api/v1/veo/record-info?taskId=' + taskId,
          {
            headers: {
              'Content-Type': 'application/json',

View on GitHub (pinned to 0f1647f749)

Solutions

  1. Check the thrown message — it usually contains the upstream msg (e.g. 'insufficient balance')
  2. Verify the API key environment variable is set and valid in the backend/orchestrator environment
  3. Check the kie.ai dashboard for quota/billing status
  4. Retry after fixing credentials; if the provider is down, wait and retry (the task is idempotent per request)

Example fix

// before
const value = await (await fetch(url, {...})).json();
if (value.code !== 200 && value.code !== 201) throw new Error(value?.msg || 'Failed to generate video');

// after: include code for diagnosis
if (value.code !== 200 && value.code !== 201) {
  throw new Error(`Failed to generate video (code=${value.code}): ${value?.msg ?? 'unknown'}`);
}
Defensive patterns

Strategy: retry

Validate before calling

if (!process.env.KIE_API_KEY) throw new Error('KIE_API_KEY not configured'); // fail fast before calling veo3

Type guard

const hasVeoCredentials = (): boolean => !!process.env.KIE_API_KEY;

Try / catch

try { await veo3.process(prompt); } catch (e) { if (/Failed to generate video/.test(String(e))) { await sleep(5000); return veo3.process(prompt); } throw e; }

Prevention

When it happens

Trigger: POST to api.kia.ai/api/v1/veo/create-task with an invalid/expired KIE API key, exhausted credits, disallowed aspect ratio or prompt content, or a provider outage. Any non-200/201 code triggers it.

Common situations: Missing or expired VITE/ENV KIE_API_KEY after redeploy; free-tier quota used up; content moderation rejecting the prompt; kie.ai API changes or downtime.

Related errors


AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27). Data as JSON: /api/errors/9de4ca4a32a0629b. Report an issue: GitHub.