Files
automate-for-growth/09-advanced-automation-api/README.md
T
2025-12-05 14:24:35 -05:00

14 KiB

Module 9: Advanced Automation - API

Welcome to Module 9! This module is for developers and advanced users who want to build custom automation workflows. If you're not technical, that's okay - you can skip this module and still succeed with everything else. But if you want to integrate automation into your own tools or build custom solutions, this is for you.

Introduction to the Sora API

API Overview (What is an API?)

Simple Explanation:

Think of an API like a waiter at a restaurant:

  • You (the customer): Want food
  • The Waiter (API): Takes your order to the kitchen
  • The Kitchen (Platform): Makes your food
  • The Waiter: Brings your food back to you

An API lets your applications "talk" to the platform and get video generation services.

API Documentation: https://viralwavestudio.com/sora-api

Key Benefits:

1. Cost Savings

  • Up to 70% off standard OpenAI pricing
  • Real example: $0.34 per video vs. $1.00+ elsewhere
  • If you create 1000 videos: Save $660+ per month!

2. Custom Integration

  • Build your own automation workflows
  • Real example: Automatically generate videos when you publish a blog post

3. Scalability

  • Handle high-volume video generation
  • Real example: Generate 100+ videos in one batch

4. Flexibility

  • Customize to your specific needs
  • Real example: Create videos with your own branding automatically

5. Control

  • Full control over the generation process
  • Real example: Set up custom quality checks, automatic retries, etc.

Who Should Use the API:

  • Developers building custom tools
  • Businesses with high video volume (100+ videos/month)
  • People who want to integrate with existing systems
  • Agencies managing multiple clients
  • Beginners just starting out (use the platform first!)
  • People creating occasional videos (platform is easier)

Why Use the API vs. Platform

Platform Use Cases:

  • Manual content creation
  • One-off video generation
  • Non-technical users
  • Quick content needs
  • Standard workflows

API Use Cases:

  • Custom automation systems
  • High-volume generation
  • Integration with other tools
  • Developer workflows
  • Advanced customization
  • Cost optimization

When to Use API:

  • Generating 100+ videos regularly
  • Building custom tools
  • Integrating with existing systems
  • Need for programmatic control
  • Cost optimization at scale

Cost Savings: 70% Off OpenAI Pricing

Pricing Comparison:

Standard OpenAI Pricing:

  • 10-second video: ~$1.00
  • 15-second video: ~$1.50
  • High-volume: No discounts

API Pricing:

  • 10-second video: ~$0.34
  • 15-second video: ~$0.51
  • High-volume: Additional savings
  • Savings: 66-70%

Volume Savings:

  • Higher volumes = better rates
  • Bulk operations = efficiency
  • Reduced overhead = lower costs
  • Scale benefits = more savings

ROI Calculation:

  • 100 videos: Save $66-70
  • 1000 videos: Save $660-700
  • Monthly savings: Significant
  • Annual savings: Substantial

API Access Requirements

Getting Started:

  1. Sign up for API access
  2. Choose appropriate plan
  3. Get API credentials
  4. Review documentation
  5. Make first API call

Plan Requirements:

  • Powerhouse plan includes API access
  • Separate API plans available
  • Usage-based pricing
  • Token system

Credentials Needed:

  • API key
  • Secret key (if required)
  • Endpoint URLs
  • Authentication method

Getting API Credentials

API Documentation Overview

Documentation Sections:

  • Authentication
  • Endpoints
  • Request/response formats
  • Code examples
  • Error handling
  • Rate limits
  • Best practices

Accessing Documentation:

Authentication Setup

Authentication Methods:

  • API key in headers
  • Bearer token
  • OAuth (if available)
  • Secret key (if required)

Setting Up Authentication:

  1. Get API Credentials

    • Log into your account
    • Navigate to API settings
    • Generate API key
    • Save credentials securely
  2. Configure Authentication

    • Add API key to requests
    • Set up headers correctly
    • Test authentication
    • Handle errors
  3. Secure Credentials

    • Never expose in code
    • Use environment variables
    • Rotate keys regularly
    • Monitor usage

Best Practices:

  • Store credentials securely
  • Use environment variables
  • Never commit to git
  • Rotate regularly
  • Monitor access

Making Your First API Call

Simple Example (Python):

import requests

api_key = "your_api_key_here"
url = "https://api.viralwavestudio.com/v1/video/generate"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "prompt": "A professional office setting with a person working on a laptop",
    "duration": 10,
    "style": "professional"
}

response = requests.post(url, headers=headers, json=data)
video_url = response.json()["video_url"]
print(f"Video generated: {video_url}")

Simple Example (JavaScript):

const apiKey = 'your_api_key_here';
const url = 'https://api.viralwavestudio.com/v1/video/generate';

fetch(url, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'A professional office setting with a person working on a laptop',
    duration: 10,
    style: 'professional'
  })
})
.then(response => response.json())
.then(data => {
  console.log('Video generated:', data.video_url);
})
.catch(error => {
  console.error('Error:', error);
});

Video Generation via API

API Endpoints:

Generate Video:

  • POST /v1/video/generate
  • Request: prompt, duration, style
  • Response: video_url, status, metadata

Check Status:

  • GET /v1/video/status/{video_id}
  • Request: video_id
  • Response: status, progress, video_url

List Videos:

  • GET /v1/video/list
  • Request: filters, pagination
  • Response: videos array, metadata

Request Parameters:

  • prompt: Text description of video
  • duration: Video length (10 or 15 seconds)
  • style: Visual style preference
  • quality: Output quality setting
  • format: Video format (mp4, etc.)

Response Format:

{
  "video_id": "vid_123456",
  "status": "processing",
  "video_url": "https://...",
  "estimated_completion": "2024-01-01T12:00:00Z",
  "cost": 0.34
}

Error Handling and Best Practices

Common Errors:

  • Authentication failures
  • Invalid parameters
  • Rate limit exceeded
  • Processing errors
  • Network issues

Error Handling:

try:
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status()
    result = response.json()
except requests.exceptions.HTTPError as e:
    if e.response.status_code == 401:
        print("Authentication failed")
    elif e.response.status_code == 429:
        print("Rate limit exceeded")
    else:
        print(f"Error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Best Practices:

  • Always handle errors
  • Implement retry logic
  • Log errors for debugging
  • Monitor API usage
  • Respect rate limits
  • Validate inputs
  • Use async for bulk operations

Building Custom Automation Workflows

Integrating with Other Tools

Zapier Integration:

  1. Create Zapier Account

    • Sign up for Zapier
    • Connect API account
    • Set up authentication
  2. Create Zap

    • Trigger: Your event (new blog post, etc.)
    • Action: API call to generate video
    • Follow-up: Post to social media
  3. Configure Workflow

    • Map data fields
    • Set up conditions
    • Test workflow
    • Activate

Make.com Integration:

  1. Create Make.com Account

    • Sign up for Make.com
    • Connect API
    • Set up scenario
  2. Build Scenario

    • Trigger module
    • API module (video generation)
    • Action modules (posting, etc.)
  3. Automate Workflow

    • Test scenario
    • Schedule or trigger
    • Monitor execution

Custom Scheduling Systems

Building Your Own Scheduler:

Features:

  • Content queue management
  • Automated video generation
  • Multi-platform posting
  • Performance tracking
  • Analytics integration

Architecture:

  • Database for content queue
  • API integration for generation
  • Scheduling system
  • Posting automation
  • Analytics tracking

Example Workflow:

  1. Add content to queue
  2. System generates video via API
  3. Video processed and optimized
  4. Scheduled for posting
  5. Posted to platforms
  6. Performance tracked

Advanced Reporting

Custom Dashboard:

Metrics to Track:

  • Videos generated
  • Costs per video
  • Processing times
  • Success rates
  • Platform performance
  • ROI metrics

Building Dashboard:

  • Collect API data
  • Store in database
  • Create visualizations
  • Real-time updates
  • Export capabilities

Reporting Features:

  • Daily/weekly/monthly reports
  • Cost analysis
  • Performance trends
  • ROI calculations
  • Custom metrics

Building Custom Dashboards

Dashboard Components:

  • Video generation stats
  • Cost tracking
  • Performance metrics
  • Queue status
  • Error monitoring
  • Usage analytics

Technology Stack:

  • Backend: Python/Node.js
  • Database: PostgreSQL/MySQL
  • Frontend: React/Vue
  • Charts: Chart.js/D3.js
  • API: REST/GraphQL

Implementation:

  • API integration
  • Data collection
  • Real-time updates
  • Visualizations
  • User interface

API Use Cases and Examples

E-commerce Product Video Automation

Use Case:

  • Generate product videos automatically
  • Update when products change
  • Scale to thousands of products
  • Cost-effective production

Workflow:

  1. Product data from e-commerce platform
  2. Generate video via API
  3. Add to product page
  4. Post to social media
  5. Track performance

Example Code:

def generate_product_video(product):
    prompt = f"Professional product showcase of {product.name}, {product.description}"
    video = api.generate_video(
        prompt=prompt,
        duration=10,
        style="ecommerce"
    )
    return video

News Content Video Generation

Use Case:

  • Convert news articles to videos
  • Automated video creation
  • Real-time news videos
  • Scalable production

Workflow:

  1. News article published
  2. Extract key information
  3. Generate video via API
  4. Publish to platforms
  5. Track engagement

Example Code:

def news_to_video(article):
    prompt = f"News video about {article.headline}. {article.summary}"
    video = api.generate_video(
        prompt=prompt,
        duration=15,
        style="news"
    )
    return video

Social Media Management Tools Integration

Use Case:

  • Integrate with Hootsuite, Buffer, etc.
  • Automated video generation
  • Seamless workflow
  • Multi-platform posting

Workflow:

  1. Content planned in tool
  2. Trigger video generation
  3. Video added to queue
  4. Scheduled and posted
  5. Performance tracked

Content Management System Integration

Use Case:

  • WordPress, Drupal, etc.
  • Blog post → video automation
  • SEO-optimized videos
  • Automated publishing

Workflow:

  1. Blog post published
  2. Generate video summary
  3. Add to post
  4. Post to social media
  5. Track performance

Custom Video Generation Pipelines

Pipeline Components:

  • Content input
  • Video generation
  • Processing and optimization
  • Quality control
  • Distribution
  • Analytics

Example Pipeline:

class VideoPipeline:
    def __init__(self, api_key):
        self.api = VideoAPI(api_key)
    
    def process(self, content):
        # Generate video
        video = self.api.generate(content)
        
        # Process video
        processed = self.optimize(video)
        
        # Quality check
        if self.quality_check(processed):
            # Distribute
            self.distribute(processed)
            return processed
        else:
            return None

Cost Optimization with API

Understanding API Pricing

Pricing Structure:

  • Per-video pricing
  • Volume discounts
  • Token system
  • Usage-based billing

Cost Factors:

  • Video duration
  • Quality settings
  • Processing complexity
  • Volume discounts

Pricing Tiers:

  • Starter: Basic pricing
  • Pro: Volume discounts
  • Enterprise: Custom pricing

Token Management Strategies

Token System:

  • Tokens = currency
  • Monthly allocation
  • Usage tracking
  • Overage handling

Management Strategies:

  • Monitor usage regularly
  • Optimize video generation
  • Batch operations
  • Cache when possible
  • Plan usage monthly

Optimization:

  • Use appropriate duration
  • Optimize prompts
  • Batch requests
  • Cache results
  • Monitor costs

Bulk API Operations

Bulk Generation:

def bulk_generate_videos(prompts):
    videos = []
    for prompt in prompts:
        video = api.generate_video(prompt=prompt)
        videos.append(video)
    return videos

Best Practices:

  • Batch requests when possible
  • Use async operations
  • Implement rate limiting
  • Handle errors gracefully
  • Monitor progress

Cost Comparison: API vs. Platform

Platform Costs:

  • Standard platform pricing
  • No volume discounts
  • Manual operations
  • Higher per-video cost

API Costs:

  • 70% lower pricing
  • Volume discounts
  • Automated operations
  • Lower per-video cost

Savings Example:

  • 100 videos: $66-70 saved
  • 1000 videos: $660-700 saved
  • Monthly: Significant savings
  • Annual: Substantial ROI

Maximizing Value with API Access

Value Maximization:

  • Automate everything possible
  • Batch operations
  • Optimize prompts
  • Monitor usage
  • Scale efficiently

ROI Strategies:

  • High-volume generation
  • Automated workflows
  • Cost optimization
  • Efficiency gains
  • Time savings

Advanced API Techniques

Async Operations

Async Video Generation:

import asyncio
import aiohttp

async def generate_video_async(session, prompt):
    async with session.post(url, headers=headers, json={"prompt": prompt}) as response:
        return await response.json()

async def bulk_generate(prompts):
    async with aiohttp.ClientSession() as session:
        tasks = [generate_video_async(session, p) for p in prompts]
        return await asyncio.gather(*tasks)

Webhook Integration

Setting Up Webhooks:

  • Receive notifications
  • Real-time updates
  • Event-driven workflows
  • Automated processing

Webhook Implementation:

  • Set webhook URL
  • Handle events
  • Process notifications
  • Update systems

Rate Limiting

Handling Rate Limits:

  • Monitor rate limits
  • Implement backoff
  • Queue requests
  • Batch operations
  • Respect limits

Next Steps

You've mastered API integration. Next, learn about team collaboration and enterprise features in Module 10: Team Collaboration.