DEV Community

q2408808
q2408808

Posted on • Originally published at nexa-api.com

Veo 3.1 API Tutorial — Generate AI Videos via NexaAPI (Python + JS Guide)

Veo 3.1 API Tutorial — Generate AI Videos via NexaAPI (Python + JS Guide)

Google just dropped Veo 3.1 — the most advanced video generation model in the Gemini API. Here's how to access it in under 5 minutes, without Google Cloud setup, without complex billing, and at 5x cheaper than direct Vertex AI pricing.

What is Veo 3.1?

Veo 3.1 is Google DeepMind's latest video generation model, supporting:

  • Text-to-video generation with cinematic quality
  • Image-to-video animation
  • Audio generation built-in
  • Up to 30-second videos at 1080p
  • Aspect ratio control (16:9, 9:16)

Why Use NexaAPI Instead of Raw Gemini API?

Feature Direct Gemini API NexaAPI
Setup Google Cloud + billing 2-minute signup
Pricing $0.40/request $0.15/request
Models Veo only 56+ models
Auth Complex OAuth Simple API key
Free tier Limited Yes

Installation

pip install nexaapi
Enter fullscreen mode Exit fullscreen mode
npm install nexaapi
Enter fullscreen mode Exit fullscreen mode

Python Tutorial: Text-to-Video with Veo 3.1

# pip install nexaapi
from nexaapi import NexaAPI

# Get your API key at https://nexa-api.com
client = NexaAPI(api_key='YOUR_API_KEY')

# Text-to-Video with Veo 3.1
response = client.video.generate(
    model='veo-3.1',
    prompt='A cinematic aerial shot of a futuristic city at sunset, 4K quality',
    aspect_ratio='16:9',
    resolution='1080p'
)

print(response.video_url)

# Save video locally
with open('output.mp4', 'wb') as f:
    f.write(response.content)
print('Video saved as output.mp4')
Enter fullscreen mode Exit fullscreen mode

Python Tutorial: Image-to-Video with Veo 3.1

from nexaapi import NexaAPI

client = NexaAPI(api_key='YOUR_API_KEY')

# Image-to-Video with Veo 3.1
response = client.video.generate(
    model='veo-3.1',
    prompt='The scene comes to life with dramatic motion and cinematic lighting',
    image_url='https://example.com/your-image.jpg',
    aspect_ratio='16:9',
    resolution='1080p'
)

print(f'Image-to-Video URL: {response.video_url}')
Enter fullscreen mode Exit fullscreen mode

JavaScript Tutorial: Veo 3.1 Video Generation

// npm install nexaapi
import NexaAPI from 'nexaapi';
import fs from 'fs';

// Get your API key at https://nexa-api.com
const client = new NexaAPI({ apiKey: 'YOUR_API_KEY' });

async function generateVideo() {
  // Text-to-Video with Veo 3.1
  const response = await client.video.generate({
    model: 'veo-3.1',
    prompt: 'A cinematic aerial shot of a futuristic city at sunset, 4K quality',
    aspectRatio: '16:9',
    resolution: '1080p'
  });

  console.log('Video URL:', response.videoUrl);
  fs.writeFileSync('output.mp4', response.content);
  console.log('Video saved as output.mp4');
}

generateVideo().catch(console.error);
Enter fullscreen mode Exit fullscreen mode

JavaScript Tutorial: Image-to-Video

import NexaAPI from 'nexaapi';

const client = new NexaAPI({ apiKey: 'YOUR_API_KEY' });

async function imageToVideo() {
  const response = await client.video.generate({
    model: 'veo-3.1',
    prompt: 'The scene comes to life with dramatic motion',
    imageUrl: 'https://example.com/your-image.jpg',
    aspectRatio: '16:9'
  });

  console.log('Image-to-Video URL:', response.videoUrl);
}

imageToVideo().catch(console.error);
Enter fullscreen mode Exit fullscreen mode

Advanced: Aspect Ratio & Resolution Control

from nexaapi import NexaAPI

client = NexaAPI(api_key='YOUR_API_KEY')

# Vertical video for TikTok/Reels (9:16)
vertical_video = client.video.generate(
    model='veo-3.1',
    prompt='A person dancing in a colorful studio',
    aspect_ratio='9:16',
    resolution='1080p'
)

# Standard widescreen (16:9)
widescreen_video = client.video.generate(
    model='veo-3.1',
    prompt='Epic mountain landscape timelapse',
    aspect_ratio='16:9',
    resolution='720p'  # Use 720p for faster generation
)

print(f'Vertical: {vertical_video.video_url}')
print(f'Widescreen: {widescreen_video.video_url}')
Enter fullscreen mode Exit fullscreen mode

Pricing Comparison

Provider Price per Request Free Tier
Google Vertex AI (direct) ~$0.40 Limited
NexaAPI $0.15 Yes
Other aggregators $0.20-0.35 No

NexaAPI is 2.7x cheaper than direct Google Vertex AI pricing.

FAQ

Q: Do I need a Google Cloud account?
No! NexaAPI handles all the Google Cloud complexity. You just need a NexaAPI key.

Q: Is there a free tier?
Yes! Sign up at nexa-api.com for free credits.

Q: What's the maximum video length?
Veo 3.1 supports up to 30 seconds at 1080p.

Q: Can I generate videos with audio?
Yes, Veo 3.1 includes built-in audio generation.

Get Started

  1. 🚀 Sign up free at nexa-api.com
  2. 📦 Install: pip install nexaapi or npm install nexaapi
  3. 🎬 Generate your first video!

Resources


Generate AI videos with Veo 3.1 today — no Google Cloud setup, no complex billing, just 5 lines of code.

Top comments (0)