Skip to main content

Error Response Format

Error responses return a JSON body with the appropriate HTTP status code:
{
  "message": "Invalid request parameters"
}

Insufficient Credits (402)

The 402 response includes additional fields:
{
  "message": "Insufficient credits",
  "required": 200,
  "available": 10
}
required — credits needed for the task. available — your current balance.

HTTP Status Codes

CodeMeaningDescription
200SuccessRequest completed
400Bad RequestInvalid parameters or inputs
401UnauthorizedMissing or invalid API key
402Payment RequiredInsufficient credits
403ForbiddenAPI access not enabled, or querying another user’s task
404Not FoundTask ID does not exist
500Server ErrorInternal error, safe to retry

Common Error Messages

messageWhat to do
Missing Authorization headerAdd Authorization: Bearer YOUR_API_KEY header
Invalid API KeyCheck your API key in Account
Insufficient creditsAdd credits in Account
Invalid request parametersCheck required fields and model name
Invalid inputs for modelVerify parameter types and values
Missing taskId parameterProvide taskId query parameter
Task not foundVerify the task ID
API access not enabled for this accountContact support to request developer access
Access deniedYou can only query your own tasks

Task Failure States

When polling task status via Get Task Status, check the status field:
  • waiting — task queued, keep polling
  • generating — in progress, keep polling
  • success — done, read output array for video URL
  • fail — failed, read error string for details

Fail Response Example

{
  "taskId": "task_clxxxxxx",
  "model": "seedance-20",
  "status": "fail",
  "error": "Task execution failed"
}
A fail status means the generation itself failed. The HTTP response is still 200 — the error details are in the error field.

Basic Error Handling

const response = await fetch('https://seedance2-pro.com/api/v1/jobs/createTask', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.SEEDANCE_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'seedance-20',
    inputs: { prompt: 'A sunset over the ocean', resolution: '1280x720', duration: '5s' }
  })
});

const data = await response.json();

if (!response.ok) {
  console.error(`Error ${response.status}: ${data.message}`);
  if (response.status === 402) {
    console.error(`Need ${data.required} credits, have ${data.available}`);
  }
}

Retry Logic

Retry on server errors (500) with exponential backoff:
async function createTaskWithRetry(inputs, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    const response = await fetch('https://seedance2-pro.com/api/v1/jobs/createTask', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.SEEDANCE_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ model: 'seedance-20', inputs })
    });

    const data = await response.json();

    if (response.ok) return data;

    // Only retry on 500 server errors
    if (response.status >= 500 && i < maxRetries - 1) {
      await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
      continue;
    }

    throw new Error(`${response.status}: ${data.message}`);
  }
}

When to Retry

DO retry: 500 (server error), network timeouts DON’T retry: 400 (bad request), 401 (unauthorized), 402 (insufficient credits), 403 (forbidden)

Complete Example

async function generateVideo(prompt) {
  // 1. Create task
  const task = await createTaskWithRetry({
    prompt,
    resolution: '1280x720',
    duration: '5s'
  });

  console.log('Task created:', task.taskId);

  // 2. Poll for completion
  const startTime = Date.now();
  while (Date.now() - startTime < 300000) {
    const response = await fetch(
      `https://seedance2-pro.com/api/v1/jobs/recordInfo?taskId=${task.taskId}`,
      { headers: { 'Authorization': `Bearer ${process.env.SEEDANCE_API_KEY}` } }
    );

    const data = await response.json();

    if (data.status === 'success') {
      return data.output; // [{url, width, height}]
    }
    if (data.status === 'fail') {
      throw new Error(data.error || 'Generation failed');
    }

    await new Promise(resolve => setTimeout(resolve, 5000));
  }

  throw new Error('Task timeout');
}

Next Steps