Text to Video

Text-to-Video

Generate high-quality videos from natural language descriptions using the Bach video generation model.


Create a Text-to-Video Task

Submit a text prompt to initiate an asynchronous video generation task. The API returns a task_id that you can use to poll for the result.

Request URL

Copy
POST https://api-gen-na.bach.art/api/vdr/videos/text2video

Request Headers

HeaderValue
AuthorizationBearer <your_api_token>
Content-Typeapplication/json

Request Body

json
Copy
{
  "model_name": "bach-1.0-preview",
  "prompt": "A beautiful sunset over the ocean, waves crashing against the shore",
  "negative_prompt": "blurry, low quality, distorted",
  "resolution": "1080p",
  "aspect_ratio": "16:9",
  "duration": 6,
  "cfg_scale": 7.5,
  "enhance_prompt": true,
  "generate_audio": false,
  "audio_prompt": "ocean waves, seagulls, gentle breeze",
  "callback_url": "https://your-domain.com/callback",
  "seed": 42
}

Request Parameters

ParameterTypeRequiredDefaultDescription
model_namestringYesModel identifier. Currently only bach-1.0-preview is supported
promptstringYesText description of the video to generate (max 10,000 characters)
negative_promptstringNo""Elements to exclude from the generated video (max 10,000 characters)
resolutionstringYesOutput resolution: 720p or 1080p (case-sensitive)
aspect_ratiostringNo"16:9"Output aspect ratio: 16:9, 9:16, or 1:1
durationintegerYesVideo duration in seconds. (range:1~6)
fpsintegerNo30Frame rate:30 or 24. Currently default at 30
cfg_scalefloatNo5.0Classifier-free guidance scale. Higher values increase prompt adherence (range: 1.015.0)
enhance_promptbooleanNotrueAutomatically enhance the prompt for improved visual quality
generate_audiobooleanNofalseGenerate a synchronized audio track for the video
audio_promptstringNo""Text description for audio generation (max 200 characters). Only effective when generate_audio is true
callback_urlstringNo""Webhook URL for receiving task completion notifications (max 500 characters)
seedintegerNoRandomRandom seed for reproducible generation (range: 010,000,000)

Response

Success (HTTP 200):

json
Copy
{
  "code": 200,
  "message": "Success",
  "data": {
    "task_id": "660e8400-e29b-41d4-a716-446655440001",
    "create_at": 1709251200
  }
}
FieldTypeDescription
codeintegerBusiness response code
messagestringResponse message
data.task_idstringUnique task identifier (UUID)
data.create_atlongTask creation timestamp (Unix epoch, seconds)

Error Examples:

ScenarioHTTP StatusCodeMessage
Missing prompt4001000Please provide a prompt.
Invalid duration4001000Duration must be 6 seconds. Please refer to the API documentation for details.
Insufficient credits4031302Insufficient credit package.

For a complete list of error codes, see Response Codes.


Query a Text-to-Video Task

Retrieve the status and result of a previously submitted text-to-video task.

Request URL

Copy
GET https://api-gen-na.bach.art/api/vdr/videos/text2video/{task_id}

Request Headers

HeaderValue
AuthorizationBearer <your_api_token>

Path Parameters

ParameterTypeRequiredDescription
task_idstringYesTask identifier returned by the creation endpoint

Request Example

bash
Copy
curl -X GET "https://api-gen-na.bach.art/api/vdr/videos/text2video/660e8400-e29b-41d4-a716-446655440001" \
  -H "Authorization: Bearer <your_api_token>"

Response

Success (HTTP 200):

json
Copy
{
  "code": 200,
  "message": "Success",
  "data": {
    "task_id": "660e8400-e29b-41d4-a716-446655440001",
    "status": "TASK_SUCCEEDED",
    "message": "Video generation completed successfully",
    "video_url": "https://cdn.bach.art/videos/660e8400-e29b-41d4-a716-446655440001.mp4"
  }
}
FieldTypeDescription
data.task_idstringUnique task identifier
data.statusstringCurrent task status. See Task Status
data.messagestringHuman-readable status message
data.video_urlstringDownload URL for the generated video. Present only when status is TASK_SUCCEEDED

Task Status Values

StatusDescription
TASK_PENDINGTask is queued, awaiting processing
TASK_PROCESSINGVideo generation is in progress
TASK_SUCCEEDEDGeneration completed; video_url is available
TASK_FAILEDGeneration failed; check message for details

Webhook Callback

If you provide a callback_url when creating a task, the API sends an HTTP POST request to that URL upon task completion.

Callback Payload:

json
Copy
{
  "task_id": "660e8400-e29b-41d4-a716-446655440001",
  "status": "TASK_SUCCEEDED",
  "video_url": "https://cdn.bach.art/videos/660e8400-e29b-41d4-a716-446655440001.mp4",
  "created_at": 1709251200,
  "completed_at": 1709251320
}

Note: Your callback endpoint must return HTTP 200 within 5 seconds. Failed callbacks are retried up to 3 times with exponential backoff.


Code Examples

Python

python
Copy
import requests
import time

API_BASE = "https://api-gen-na.bach.art/api/vdr"
API_TOKEN = "<your_api_token>"

headers = {
    "Authorization": f"Bearer {API_TOKEN}",
    "Content-Type": "application/json"
}

# Step 1: Create a text-to-video task
payload = {
    "model_name": "bach-1.0-preview",
    "prompt": "A beautiful sunset over the ocean, waves crashing against the shore",
    "resolution": "1080p",
    "aspect_ratio": "16:9",
    "duration": 6,
    "enhance_prompt": True
}

response = requests.post(
    f"{API_BASE}/videos/text2video",
    headers=headers,
    json=payload
)

task_id = response.json()["data"]["task_id"]
print(f"Task submitted: {task_id}")

# Step 2: Poll for completion
while True:
    status_response = requests.get(
        f"{API_BASE}/videos/text2video/{task_id}",
        headers=headers
    )

    result = status_response.json()["data"]
    status = result["status"]

    if status  "TASK_SUCCEEDED":
        print(f"Video ready: {result['video_url']}")
        break
    elif status  "TASK_FAILED":
        print(f"Generation failed: {result['message']}")
        break
    else:
        print(f"Status: {status}, waiting...")
        time.sleep(10)

cURL

bash
Copy
# Create task
curl -X POST "https://api-gen-na.bach.art/api/vdr/videos/text2video" \
  -H "Authorization: Bearer <your_api_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "model_name": "bach-1.0-preview",
    "prompt": "A beautiful sunset over the ocean, waves crashing against the shore",
    "resolution": "1080p",
    "aspect_ratio": "16:9",
    "duration": 6
  }'

# Query task status
curl -X GET "https://api-gen-na.bach.art/api/vdr/videos/text2video/{task_id}" \
  -H "Authorization: Bearer <your_api_token>"

Node.js

javascript
Copy
const axios = require('axios');

const API_BASE = 'https://api-gen-na.bach.art/api/vdr';
const API_TOKEN = '<your_api_token>';

const headers = {
  'Authorization': `Bearer ${API_TOKEN}`,
  'Content-Type': 'application/json'
};

async function generateVideo() {
  // Step 1: Create task
  const submitResponse = await axios.post(
    `${API_BASE}/videos/text2video`,
    {
      model_name: 'bach-1.0-preview',
      prompt: 'A beautiful sunset over the ocean, waves crashing against the shore',
      resolution: '1080p',
      aspect_ratio: '16:9',
      duration: 6
    },
    { headers }
  );

  const taskId = submitResponse.data.data.task_id;
  console.log(`Task submitted: ${taskId}`);

  // Step 2: Poll for completion
  while (true) {
    const statusResponse = await axios.get(
      `${API_BASE}/videos/text2video/${taskId}`,
      { headers }
    );

    const { status, video_url, message } = statusResponse.data.data;

    if (status = 'TASK_SUCCEEDED') {
      console.log(`Video ready: ${video_url}`);
      return video_url;
    } else if (status = 'TASK_FAILED') {
      throw new Error(`Generation failed: ${message}`);
    }

    console.log(`Status: ${status}, waiting...`);
    await new Promise(resolve => setTimeout(resolve, 10000));
  }
}

generateVideo().catch(console.error);
Previous
Capability Map
Next
Image to Video
On this page