Veo 3.1 API Tutorial: Complete Python & JavaScript Guide (2026)
TL;DR: Google's Veo 3.1 is the most advanced AI video generation model available. This guide covers every feature — text-to-video, image-to-video, aspect ratio control, resolution control, scene extension, and reference images — using NexaAPI for instant access at 67% lower cost than direct Google API pricing.
What is Veo 3.1?
Veo 3.1 is Google's state-of-the-art AI video generation model (updated January 2026). It generates high-fidelity 8-second videos at up to 4K resolution with native audio — the first video generation model to natively synchronize sound effects, music, and dialogue with video content.
Key Features:
- Native Audio Generation: Natural conversations, synchronized sound effects
- Text-to-Video & Image-to-Video
- Reference Images: Guide generation with up to 3 reference images
- Scene Extension: Extend videos up to 1 minute+
- Resolution: 720p, 1080p, or 4K
- Aspect Ratios: 16:9, 9:16, 1:1
The Problem with Direct Google API
Google's Veo 3.1 API costs $0.40/second ($3.20 per 8-second 1080p video), requires GCP setup, and has no free tier.
NexaAPI solves this: same Veo 3.1 model, instant access, $0.1333/second (67% cheaper), with a free tier.
Installation
# Python
pip install nexaapi
# JavaScript
npm install nexaapi
Get your API key at nexa-api.com — no credit card required for free tier.
Feature 1: Text-to-Video
Python
from nexaapi import NexaAPI
client = NexaAPI(api_key='YOUR_API_KEY')
response = client.video.generate(
model='veo-3.1',
prompt='A timelapse of a flower blooming in a garden, macro photography, golden hour lighting'
)
print('Video URL:', response.video_url)
JavaScript
import NexaAPI from 'nexaapi';
const client = new NexaAPI({ apiKey: 'YOUR_API_KEY' });
const response = await client.video.generate({
model: 'veo-3.1',
prompt: 'A timelapse of a flower blooming in a garden, macro photography'
});
console.log('Video URL:', response.videoUrl);
Feature 2: Aspect Ratio Control
# Portrait for TikTok/Reels
portrait = client.video.generate(
model='veo-3.1',
prompt='A person walking through neon-lit Tokyo at night',
aspect_ratio='9:16'
)
# Landscape for YouTube
landscape = client.video.generate(
model='veo-3.1',
prompt='Epic mountain landscape with storm clouds',
aspect_ratio='16:9'
)
# Square for Instagram
square = client.video.generate(
model='veo-3.1',
prompt='Coffee being poured in slow motion',
aspect_ratio='1:1'
)
Feature 3: Resolution Control (720p, 1080p, 4K)
# 4K cinematic quality
uhd_video = client.video.generate(
model='veo-3.1',
prompt='A majestic eagle soaring over snow-capped mountains, golden hour',
resolution='4k',
aspect_ratio='16:9'
)
print('4K video:', uhd_video.video_url)
Feature 4: Image-to-Video
# Animate a still image
product_video = client.video.generate(
model='veo-3.1',
prompt='The product rotates slowly on a white background, studio lighting',
image_url='https://example.com/product.jpg',
aspect_ratio='1:1'
)
print('Animated video:', product_video.video_url)
// JavaScript image-to-video
const i2v = await client.video.generate({
model: 'veo-3.1',
prompt: 'The landscape comes alive with gentle wind and moving clouds',
imageUrl: 'https://example.com/landscape.jpg',
aspectRatio: '16:9'
});
console.log('Image-to-Video:', i2v.videoUrl);
Feature 5: Reference Images
# Use up to 3 reference images for consistency
character_video = client.video.generate(
model='veo-3.1',
prompt='The character walks through a futuristic city, confident stride',
reference_images=[
'https://example.com/character-front.jpg',
'https://example.com/character-side.jpg'
],
aspect_ratio='9:16'
)
Feature 6: Batch Generation
import asyncio
from nexaapi import AsyncNexaAPI
async def generate_batch():
client = AsyncNexaAPI(api_key='YOUR_API_KEY')
prompts = [
'A rocket launching into space, cinematic',
'A chef preparing sushi in a professional kitchen',
'A sports car drifting on a mountain road at sunset'
]
tasks = [
client.video.generate(model='veo-3.1', prompt=p, aspect_ratio='16:9')
for p in prompts
]
results = await asyncio.gather(*tasks)
for i, result in enumerate(results):
print(f'Video {i+1}: {result.video_url}')
asyncio.run(generate_batch())
// JavaScript batch with Promise.all
const prompts = [
'A rocket launching into space',
'A chef preparing sushi',
'Sports car drifting at sunset'
];
const results = await Promise.all(
prompts.map(prompt => client.video.generate({ model: 'veo-3.1', prompt, aspectRatio: '16:9' }))
);
results.forEach((r, i) => console.log(`Video ${i+1}:`, r.videoUrl));
Pricing Comparison
| Provider | Price/Second | 8s Video (1080p) | Free Tier |
|---|---|---|---|
| NexaAPI ⭐ | $0.1333 | $1.07 | ✅ Yes |
| Google Gemini API | $0.40 | $3.20 | ❌ No |
| Google Vertex AI | $0.40 | $3.20 | ❌ No |
NexaAPI saves you 67% vs direct Google API pricing.
Get Started
- Sign up free at nexa-api.com — no credit card required
- Install:
pip install nexaapi(PyPI) ornpm install nexaapi(npm) - Also available on RapidAPI
Happy building! 🎬
Official Veo 3.1 docs: ai.google.dev/gemini-api/docs/video
Top comments (0)