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
| Code | Meaning | Description |
|---|
| 200 | Success | Request completed |
| 400 | Bad Request | Invalid parameters or inputs |
| 401 | Unauthorized | Missing or invalid API key |
| 402 | Payment Required | Insufficient credits |
| 403 | Forbidden | API access not enabled, or querying another user’s task |
| 404 | Not Found | Task ID does not exist |
| 500 | Server Error | Internal error, safe to retry |
Common Error Messages
| message | What to do |
|---|
Missing Authorization header | Add Authorization: Bearer YOUR_API_KEY header |
Invalid API Key | Check your API key in Account |
Insufficient credits | Add credits in Account |
Invalid request parameters | Check required fields and model name |
Invalid inputs for model | Verify parameter types and values |
Missing taskId parameter | Provide taskId query parameter |
Task not found | Verify the task ID |
API access not enabled for this account | Contact support to request developer access |
Access denied | You 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