AI Image & Video Generation
Check the status of your image generation requests and track progress in real-time.
Check the status of a specific image generation request by its ID.
curl -X GET ulazai.com/api/v1/generate/b08cb00c-6578-4c3b-9056-cd1c0bb733cb/ \
-H "Authorization: Bearer YOUR_TOKEN_HERE"
{
"id": "b08cb00c-6578-4c3b-9056-cd1c0bb733cb",
"status": "GENERATING",
"progress": "0.47",
"created_at": "2024-07-06T15:10:00Z",
"updated_at": "2024-07-06T15:12:30Z",
"parameters": {
"prompt": "een olifant met het lichaam van een aap",
"size": "3:2",
"model": "FLUX_MAX"
},
"credits_used": 24,
"estimated_completion": "2024-07-06T15:15:00Z"
}
{
"id": "b08cb00c-6578-4c3b-9056-cd1c0bb733cb",
"status": "COMPLETED",
"progress": "1.0",
"created_at": "2024-07-06T15:10:00Z",
"updated_at": "2024-07-06T15:14:35Z",
"completed_at": "2024-07-06T15:14:35Z",
"parameters": {
"prompt": "een olifant met het lichaam van een aap",
"size": "3:2",
"model": "FLUX_MAX"
},
"credits_used": 24,
"image_url": "https://example.com/generated-images/b08cb00c-6578-4c3b-9056-cd1c0bb733cb.png",
"download_url": "ulazai.com/api/v1/generate/b08cb00c-6578-4c3b-9056-cd1c0bb733cb/download/"
}
{
"id": "b08cb00c-6578-4c3b-9056-cd1c0bb733cb",
"status": "FAILED",
"progress": "0.0",
"created_at": "2024-07-06T15:10:00Z",
"updated_at": "2024-07-06T15:12:45Z",
"failed_at": "2024-07-06T15:12:45Z",
"parameters": {
"prompt": "inappropriate content example",
"size": "3:2",
"model": "FLUX_MAX"
},
"credits_used": 0,
"error": {
"code": "CONTENT_FILTER",
"message": "Content violates our usage policies"
},
"credits_refunded": 24
}
Download the generated image file directly. Only available for completed generations.
curl -X GET ulazai.com/api/v1/generate/b08cb00c-6578-4c3b-9056-cd1c0bb733cb/download/ \
-H "Authorization: Token YOUR_TOKEN_HERE" \
-o generated-image.png
async function pollGenerationStatus(generationId, bearer) {
const maxAttempts = 120; // 10 minutes max
let attempts = 0;
let interval = 5000; // Start with 5 seconds
while (attempts < maxAttempts) {
try {
const response = await fetch(`/api/v1/generate/${generationId}/`, {
headers: {
'Authorization': `Bearer ${bearer}`
}
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
// Update UI with progress
updateProgress(data.progress);
// Check if completed
if (data.status === 'COMPLETED') {
displayImage(data.image_url);
return data;
}
// Check if failed
if (data.status === 'FAILED') {
displayError(data.error);
return data;
}
// Increase interval gradually
attempts++;
if (attempts > 12) interval = 10000; // 10 seconds after 1 minute
if (attempts > 30) interval = 30000; // 30 seconds after 5 minutes
await new Promise(resolve => setTimeout(resolve, interval));
} catch (error) {
console.error('Polling error:', error);
attempts++;
await new Promise(resolve => setTimeout(resolve, interval));
}
}
throw new Error('Generation timed out');
}
function updateProgress(progress) {
const percentage = Math.round(progress * 100);
document.getElementById('progress').textContent = `${percentage}%`;
document.getElementById('progress-bar').style.width = `${percentage}%`;
}
function displayImage(imageUrl) {
const img = document.getElementById('generated-image');
img.src = imageUrl;
img.style.display = 'block';
}
function displayError(error) {
const errorDiv = document.getElementById('error-message');
errorDiv.textContent = error.message;
errorDiv.style.display = 'block';
}