Video generation
Generate videos from text prompts using Azerion Intelligence models.
Endpoint:
POST https://api.azerion.ai/v1/videos/generation
Description
This endpoint generates videos from text descriptions. It allows you to create high-quality videos by providing detailed text prompts that describe the scenes, actions, and visual elements you want to see in the generated video.
Authentication
This endpoint requires authentication using an API key.
Request
{
"model": "veo-2",
"prompt": "A cute baby sea otter",
"n": 1
}
Request Parameters
- model (string, required): ID of the model to use for video generation. Use
veo-2
for the Veo-2 video generation model. You can use the List Models endpoint to see available models. - prompt (string, required): A text description of the desired video. The more detailed and specific the prompt, the better the generated video will match your vision. Maximum length is 4000 characters.
- n (integer, optional): The number of videos to generate. Must be between 1 and 10. Defaults to 1.
For best results, be specific and descriptive in your prompts. Include details about the scene, actions, camera movements, lighting, and any specific elements you want in the video. For example, instead of "a sea otter", try "a cute baby sea otter floating on its back in calm blue water, gently splashing with its tiny paws while sunlight filters through the surface".
Response
A successful request returns a 200 OK
status code with a JSON response body.
Standard Response
{
"videos": [
{
"base64_encoded": "AAAAIGZ0eXBpc29tAAACAGlzb21pc..."
}
]
}
Response Fields
- videos (array): An array of generated video objects.
- base64_encoded (string): The base64-encoded video data that can be decoded and saved as a video file.
Working with Base64 Video Data
The video generation API returns videos as base64-encoded strings. This encoding format allows binary video data to be transmitted as text within JSON responses. Here's how to work with this data:
What is Base64 Encoding?
Base64 encoding converts binary data (like video files) into ASCII text format. This makes it safe to include in JSON responses and ensures the data remains intact during transmission.
Decoding and Saving Videos
The generated videos are typically in MP4 format. To use the video, you need to:
- Decode the base64 string back to binary data
- Save the binary data as a video file (e.g.,
.mp4
) - Use the video file in your application
Browser Usage
For web applications, you can display the video directly in the browser without saving to disk:
// Convert base64 to data URL for direct browser display
const base64Video = result.videos[0].base64_encoded;
const dataUrl = `data:video/mp4;base64,${base64Video}`;
// Create video element
const videoElement = document.createElement('video');
videoElement.src = dataUrl;
videoElement.controls = true;
videoElement.autoplay = false;
// Add to page
document.body.appendChild(videoElement);
File Size Considerations
Base64 encoding increases the data size by approximately 33% compared to the original binary video. Consider this when:
- Storing responses in databases
- Transmitting data over networks
- Setting request/response size limits
- Decode immediately: Convert base64 to binary as soon as possible to reduce memory usage
- Error handling: Always check if the base64 string is valid before decoding
- File format: The decoded video is typically in MP4 format, but verify the format if needed
- Streaming: For large videos, consider streaming the decoded data rather than loading everything into memory
Example Request (cURL)
curl -X POST https://api.azerion.ai/v1/videos/generation \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"model": "veo-2",
"prompt": "A cute baby sea otter",
"n": 1
}'
Replace YOUR_ACCESS_TOKEN
with your actual API key or access token. Refer to the Authentication guide for details on obtaining and using your credentials.
Example Request (Python)
import requests
import os
api_key = os.environ.get("AZERION_API_KEY") # Or AZERION_ACCESS_TOKEN
url = "https://api.azerion.ai/v1/videos/generation" # Replace with your actual base URL if different
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"model": "veo-2",
"prompt": "A cute baby sea otter",
"n": 1
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
print(f"Status code: {response.status_code}")
print(f"Video data: {result['videos'][0]['base64_encoded'][:50]}...") # Print first 50 characters
# Save the video file
import base64
video_data = base64.b64decode(result['videos'][0]['base64_encoded'])
with open("generated_video.mp4", "wb") as f:
f.write(video_data)
print("Video saved as generated_video.mp4")
Example Request (Node.js)
const fetch = require('node-fetch');
const apiKey = process.env.AZERION_API_KEY; // Or AZERION_ACCESS_TOKEN
const url = 'https://api.azerion.ai/v1/videos/generation'; // Replace with your actual base URL if different
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
};
const data = {
model: 'veo-2',
prompt: 'A cute baby sea otter',
n: 1
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
console.log('Video data:', result.videos[0].base64_encoded.substring(0, 50) + '...');
// Save the video file
const fs = require('fs');
const videoData = Buffer.from(result.videos[0].base64_encoded, 'base64');
fs.writeFileSync('generated_video.mp4', videoData);
console.log('Video saved as generated_video.mp4');
})
.catch(error => console.error('Error:', error));