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
| Header | Value |
|---|---|
Authorization | Bearer <your_api_token> |
Content-Type | application/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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model_name | string | Yes | — | Model identifier. Currently only bach-1.0-preview is supported |
prompt | string | Yes | — | Text description of the video to generate (max 10,000 characters) |
negative_prompt | string | No | "" | Elements to exclude from the generated video (max 10,000 characters) |
resolution | string | Yes | — | Output resolution: 720p or 1080p (case-sensitive) |
aspect_ratio | string | No | "16:9" | Output aspect ratio: 16:9, 9:16, or 1:1 |
duration | integer | Yes | — | Video duration in seconds. (range:1~6) |
fps | integer | No | 30 | Frame rate:30 or 24. Currently default at 30 |
cfg_scale | float | No | 5.0 | Classifier-free guidance scale. Higher values increase prompt adherence (range: 1.0–15.0) |
enhance_prompt | boolean | No | true | Automatically enhance the prompt for improved visual quality |
generate_audio | boolean | No | false | Generate a synchronized audio track for the video |
audio_prompt | string | No | "" | Text description for audio generation (max 200 characters). Only effective when generate_audio is true |
callback_url | string | No | "" | Webhook URL for receiving task completion notifications (max 500 characters) |
seed | integer | No | Random | Random seed for reproducible generation (range: 0–10,000,000) |
Response
Success (HTTP 200):
json
Copy{
"code": 200,
"message": "Success",
"data": {
"task_id": "660e8400-e29b-41d4-a716-446655440001",
"create_at": 1709251200
}
}
| Field | Type | Description |
|---|---|---|
code | integer | Business response code |
message | string | Response message |
data.task_id | string | Unique task identifier (UUID) |
data.create_at | long | Task creation timestamp (Unix epoch, seconds) |
Error Examples:
| Scenario | HTTP Status | Code | Message |
|---|---|---|---|
| Missing prompt | 400 | 1000 | Please provide a prompt. |
| Invalid duration | 400 | 1000 | Duration must be 6 seconds. Please refer to the API documentation for details. |
| Insufficient credits | 403 | 1302 | Insufficient 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
| Header | Value |
|---|---|
Authorization | Bearer <your_api_token> |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
task_id | string | Yes | Task identifier returned by the creation endpoint |
Request Example
bash
Copycurl -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"
}
}
| Field | Type | Description |
|---|---|---|
data.task_id | string | Unique task identifier |
data.status | string | Current task status. See Task Status |
data.message | string | Human-readable status message |
data.video_url | string | Download URL for the generated video. Present only when status is TASK_SUCCEEDED |
Task Status Values
| Status | Description |
|---|---|
TASK_PENDING | Task is queued, awaiting processing |
TASK_PROCESSING | Video generation is in progress |
TASK_SUCCEEDED | Generation completed; video_url is available |
TASK_FAILED | Generation 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
Copyimport 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
Copyconst 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);
On this page