Error Handling
Comprehensive guide to VEO3 API error handling. Learn about error codes, response formats, troubleshooting steps, and best practices for building robust applications.
Comprehensive CoverageActionable SolutionsBest Practices
Error Response Format
All API errors follow a consistent JSON format for easy parsing and handling
Standard Error Response
Every error response includes these fields for consistent error handling
{
"success": false,
"error": "ERROR_CODE",
"message": "Human readable error message",
"details": "Additional error details (optional)",
"field": "fieldName (for validation errors)",
"value": "invalidValue (for validation errors)"
}success:
Always false for errors
error:
Machine-readable error code
message:
Human-readable description
details:
Additional context (optional)
Error Categories
Errors are categorized by HTTP status codes and specific error types
4xx Client Errors
Errors caused by invalid requests or client-side issues
| Status | Error Code | Message | Common Cause |
|---|---|---|---|
| 400 | INVALID_PROMPT | Prompt is missing or invalid | Empty or malformed prompt |
| 400 | INVALID_MODEL | Model ID is not supported | Unknown or misspelled model ID |
| 400 | VALIDATION_ERROR | Parameter validation failed | Invalid parameter values |
| 400 | MISSING_IMAGE | Image file is required but missing | Image-to-video without image file |
| 400 | INVALID_IMAGE_TYPE | Image format not supported | Non-JPEG/PNG image file |
| 400 | VIDEO_NOT_READY | Video generation not completed | Trying to download incomplete video |
| 401 | UNAUTHORIZED | API key missing or invalid | Missing or incorrect X-API-Key header |
| 402 | INSUFFICIENT_CREDITS | Not enough credits for generation | Account balance too low |
| 404 | TASK_NOT_FOUND | Video generation task not found | Invalid or expired task ID |
| 404 | NO_VIDEOS | No videos found for completed task | Task completed but videos missing |
| 413 | FILE_TOO_LARGE | Image file exceeds size limit | Image file larger than 20MB |
| 429 | RATE_LIMIT_EXCEEDED | Too many requests | Exceeded rate limits |
5xx Server Errors
Errors caused by server-side issues or temporary failures
| Status | Error Code | Message | Common Cause |
|---|---|---|---|
| 500 | INTERNAL_ERROR | Internal server error | Unexpected server error |
| 500 | GENERATION_FAILED | Video generation failed | Generation process encountered an error |
| 503 | SERVICE_UNAVAILABLE | Service temporarily unavailable | Server maintenance or overload |
| 504 | GATEWAY_TIMEOUT | Request timeout | Generation took too long to complete |
Detailed Error Examples
Common errors with full response examples and solution steps
Insufficient Credits
402INSUFFICIENT_CREDITS
Not enough credits to complete the request
Response Example
{
"success": false,
"error": "INSUFFICIENT_CREDITS",
"message": "Not enough credits to generate video",
"required": 400,
"available": 100
}Solutions
- Purchase additional credits
- Use a lower-cost model (VEO 3.0 Fast)
- Reduce sampleCount parameter
- Check your credit balance before requests
Invalid Parameters
400VALIDATION_ERROR
One or more parameters failed validation
Response Example
{
"success": false,
"error": "VALIDATION_ERROR",
"message": "Duration must be between 5 and 8 seconds",
"field": "durationSeconds",
"value": 10
}Solutions
- Check parameter ranges and constraints
- Validate data types (string vs boolean)
- Ensure required parameters are present
- Review the parameters documentation
Task Not Found
404TASK_NOT_FOUND
Video generation task could not be found
Response Example
{
"success": false,
"error": "TASK_NOT_FOUND",
"message": "Video generation task not found",
"taskId": "invalid_task_id"
}Solutions
- Verify the task ID is correct
- Check if the task has expired
- Ensure you're using the right API key
- Tasks may expire after 24 hours
Unauthorized Access
401UNAUTHORIZED
Invalid or missing API key
Response Example
{
"success": false,
"error": "UNAUTHORIZED",
"message": "API key missing or invalid"
}Solutions
- Include X-API-Key header in request
- Verify your API key is correct
- Check if your API key is active
- Ensure proper header formatting
Troubleshooting Guide
Step-by-step troubleshooting for common issues
Request Returns 400 Error
- 1Check all required parameters are present
- 2Validate parameter data types and ranges
- 3Ensure JSON is properly formatted
- 4Review the specific error message for details
Authentication Fails (401)
- 1Verify X-API-Key header is included
- 2Check your API key is correct and active
- 3Ensure no extra spaces in the API key
- 4Confirm you're using the right environment
File Upload Errors (413/400)
- 1Check image file size (max 20MB)
- 2Verify file format (JPEG or PNG only)
- 3Ensure proper multipart/form-data encoding
- 4Try with a smaller image file
Rate Limit Exceeded (429)
- 1Wait for rate limit window to reset
- 2Implement exponential backoff retry logic
- 3Reduce request frequency
- 4Consider upgrading for higher limits
Generation Fails (500)
- 1Retry the request after a short delay
- 2Try with different prompt or parameters
- 3Check service status page
- 4Contact support if issue persists
Best Practices
Implement robust error handling in your applications
Implement Proper Error Handling
Always check response status and handle errors gracefully
if (!response.ok) {
const error = await response.json();
console.error('API Error:', error.message);
// Handle specific error types
switch (error.error) {
case 'INSUFFICIENT_CREDITS':
// Redirect to billing page
break;
case 'RATE_LIMIT_EXCEEDED':
// Implement retry with backoff
break;
default:
// Show generic error message
}
}Use Exponential Backoff
Retry failed requests with increasing delays
async function retryRequest(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (error.status === 429 && i < maxRetries - 1) {
const delay = Math.pow(2, i) * 1000; // 1s, 2s, 4s
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}
throw error;
}
}
}Validate Before Sending
Check parameters client-side before making API calls
function validateParameters(params) {
if (!params.prompt || params.prompt.trim().length === 0) {
throw new Error('Prompt is required');
}
if (params.durationSeconds < 5 || params.durationSeconds > 8) {
throw new Error('Duration must be between 5 and 8 seconds');
}
if (params.sampleCount > 2) {
throw new Error('Maximum 2 videos per request');
}
}Monitor API Usage
Track error rates and response times for your application
// Log errors for monitoring
function logError(error, request) {
console.error({
timestamp: new Date().toISOString(),
error: error.error,
message: error.message,
endpoint: request.url,
statusCode: error.status
});
}Error Prevention
Proactive measures to reduce errors in your integration
Input Validation
- Validate parameters before API calls
- Check file sizes and formats
- Verify credit balance before generation
- Sanitize user inputs
Configuration
- Use environment variables for API keys
- Set appropriate request timeouts
- Implement proper logging
- Monitor API usage patterns
Next Steps
Continue learning about rate limits and see practical examples