AIStoreHub Package Vault: Veo-4-API
Package Slug: veo-4-api
Archetype: mcp_server
Upstream Repository: https://github.com/Anil-matcha/Veo-4-API
Workspace Files & Specifications (8 files)
- aistorehub.json (865 bytes)
{ "name": "Veo-4-API", "slug": "veo-4-api", "version": "1.0.0", "type": "mcp_server", "description": "Python wrapper for Veo 4 API by Google DeepMind — native 4K AI video with integrated audio, character consistency & advanced camera controls.", "owner": "community", "repository": "catalog", "github_repo_url": "https://github.com/Anil-matcha/Veo-4-API", "tags": [ "ai-video-generator", "google-deepmind", "video-generation", "mcp-server", "image-to-video", "text-to-video", "python-sdk", "google-veo", "video-api", "video-generation-api", "muapi", "camera-control", "audio-video-generation", "4k-video", "google-ai", "veo-4", "video-edit", "veo-4-api", "generative-ai", "mcp-servers", "character-consistency" ], "imported_at": "2026-11-24T20:32:27.964Z" } - INSTRUCTIONS.md (143 bytes)
Python wrapper for Veo 4 API by Google DeepMind — native 4K AI video with integrated audio, character consistency & advanced camera controls.
- mcp_server.py (6470 bytes)
import os import json from mcp.server.fastmcp import FastMCP from veo4_api import Veo4API # Initialize FastMCP server mcp = FastMCP("Veo 4 API Server") def get_api(): return Veo4API() @mcp.tool() def text_to_video(prompt: str, aspect_ratio: str = "16:9", duration: int = 8, quality: str = "4k", with_audio: bool = False, camera_control: str = None) -> str: """ Generate a native 4K video from a text prompt using Veo 4 by Google DeepMind. Veo 4 features a 3x larger Transformer than Veo 3, native 4K output, integrated audio generation, and advanced camera controls. :param prompt: Descriptive text prompt. :param aspect_ratio: Video aspect ratio (e.g., '16:9', '9:16', '1:1'). :param duration: Duration in seconds (8–30). :param quality: '1080p' or '4k'. :param with_audio: Set True to jointly generate audio alongside the video. :param camera_control: Optional camera movement (e.g., 'pan left', 'zoom in', 'orbit'). """ api = get_api() result = api.text_to_video(prompt, aspect_ratio, duration, quality, with_audio, camera_control) return json.dumps(result, indent=2) @mcp.tool() def image_to_video(prompt: str, images_list: list[str], aspect_ratio: str = "16:9", duration: int = 8, quality: str = "4k", with_audio: bool = False, camera_control: str = None) -> str: """ Animate static images into a native 4K video using Veo 4. Reference images in the prompt using @image1, @image2, etc. :param prompt: Text prompt guiding the animation. :param images_list: List of image URLs to animate. :param aspect_ratio: Video aspect ratio. :param duration: Duration in seconds (8–30). :param quality: '1080p' or '4k'. :param with_audio: Set True to jointly generate audio. :param camera_control: Optional camera movement hint. """ api = get_api() result = api.image_to_video(prompt, images_list, aspect_ratio, duration, quality, with_audio, camera_control) return json.dumps(result, indent=2) @mcp.tool() def text_to_video_with_audio(prompt: str, aspect_ratio: str = "16:9", duration: int = 8, quality: str = "4k", camera_control: str = None) -> str: """ Generate a Veo 4 video with integrated audio from a text prompt. Veo 4 generates synchronized dialogue, ambient sound, and music in one pass. Include explicit audio cues in the prompt (e.g. 'waves crashing', 'crowd cheering'). :param prompt: Text prompt. Include audio cues for richer sound. :param aspect_ratio: Video aspect ratio. :param duration: Duration in seconds (8–30). :param quality: '1080p' or '4k'. :param camera_control: Optional camera movement hint. """ api = get_api() result = api.text_to_video_with_audio(prompt, aspect_ratio, duration, quality, camera_control) return json.dumps(result, indent=2) @mcp.tool() def image_to_video_with_audio(prompt: str, images_list: list[str], aspect_ratio: str = "16:9", duration: int = 8, quality: str = "4k", camera_control: str = None) -> str: """ Animate images into a Veo 4 video with integrated audio. :param prompt: Text prompt. Reference images with @image1, @image2, etc. :param images_list: List of image URLs to animate. :param aspect_ratio: Video aspect ratio. :param duration: Duration in seconds (8–30). :param quality: '1080p' or '4k'. :param camera_control: Optional camera movement hint. """ api = get_api() result = api.image_to_video_with_audio(prompt, images_list, aspect_ratio, duration, quality, camera_control) return json.dumps(result, indent=2) @mcp.tool() def character_video(prompt: str, character_images: list[str], aspect_ratio: str = "16:9", duration: int = 8, quality: str = "4k", with_audio: bool = False) -> str: """ Generate a video with consistent character identity using Veo 4's character anchoring. Keeps faces, clothing, and distinguishing features consistent across all frames. :param prompt: Scene description. Reference the character with @image1. :param character_images: 1–3 reference image URLs of the character. :param aspect_ratio: Video aspect ratio. :param duration: Duration in seconds. :param quality: '1080p' or '4k'. :param with_audio: Set True to jointly generate audio. """ api = get_api() result = api.character_video(prompt, character_images, aspect_ratio, duration, quality, with_audio) return json.dumps(result, indent=2) @mcp.tool() def extend_video(request_id: str, prompt: str = "", duration: int = 8, quality: str = "4k") -> str: """ Extend a previously generated Veo 4 video. :param request_id: ID of the video segment to extend. :param prompt: Optional prompt to guide the continuation. :param duration: Seconds to extend by (8–30). :param quality: '1080p' or '4k'. """ api = get_api() result = api.extend_video(request_id, prompt, duration, quality) return json.dumps(result, indent=2) @mcp.tool() def video_edit(prompt: str, video_urls: list[str], images_list: list[str] = None, aspect_ratio: str = "16:9", quality: str = "4k") -> str: """ Edit an existing video using natural language with Veo 4. :param prompt: Describe the desired edits. :param video_urls: List of video URLs to edit. :param images_list: Optional reference image URLs. :param aspect_ratio: Output video aspect ratio. :param quality: '1080p' or '4k'. """ api = get_api() result = api.video_edit(prompt, video_urls, images_list, aspect_ratio, quality) return json.dumps(result, indent=2) @mcp.tool() def upload_file(file_path: str) -> str: """ Upload a local file (image or video) to MuAPI for use in generation tasks. :param file_path: Local path to the file. """ api = get_api() result = api.upload_file(file_path) return json.dumps(result, indent=2) @mcp.tool() def get_task_status(request_id: str) -> str: """ Check the status and get results of a Veo 4 generation task. :param request_id: The ID returned from a generation tool call. """ api = get_api() result = api.get_result(request_id) return json.dumps(result, indent=2) if __name__ == "__main__": mcp.run() - pyproject.toml (586 bytes)
[build-system] requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] name = "veo-4-api" version = "0.1.0" authors = [ { name="Anil Matcha" }, ] description = "A comprehensive Python wrapper for the Veo 4 API by Google DeepMind." readme = "README.md" requires-python = ">=3.7" classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ] dependencies = [ "requests", "python-dotenv", "mcp[cli]" ] [tool.setuptools] py-modules = ["veo4_api", "mcp_server"] - README.md (13697 bytes)
# Veo 4 API: Python Wrapper for Google DeepMind's AI Video Generator [](https://muapi.ai?utm_source=github&utm_medium=badge&utm_campaign=veo-4-api) [](https://pypi.org/project/veo-4-api/) [](https://github.com/Anil-matcha/Veo-4-API/stargazers) [](https://opensource.org/licenses/MIT) [](https://www.python.org/downloads/) The most comprehensive Python wrapper for the **Veo 4 API** (developed by Google DeepMind), delivered via [muapi.ai](https://muapi.ai?utm_source=github&utm_medium=readme&utm_campaign=veo-4-api). Generate native 4K AI videos up to 30 seconds with integrated audio, character consistency, and advanced camera controls — Google's most powerful video generation model. Join subreddit [Veo4](https://www.reddit.com/r/Veo4_/) for discussion > 🌊 **Also explore these top AI video models:** > - [Seedance 2.0 API](https://github.com/Anil-matcha/Seedance-2.0-API) — ByteDance's cinematic 2K video model with character sheets & omni-reference > - [HappyHorse 1.0 API](https://github.com/Anil-matcha/HappyHorse-1.0-API) — Alibaba's #1 ranked model (1392 Elo I2V) with native 1080p & integrated audio ## Related Projects - [Veo 4 on MuAPI](https://muapi.ai/veo-4) — Model landing page for the wrapper's video and audio workflows. - [Veo 4 text-to-video playground](https://muapi.ai/playground/veo-4-text-to-video) — Try Veo 4 directly in the browser. - [MiniMax-H3-API](https://github.com/Anil-matcha/MiniMax-H3-API) — Python SDK for MiniMax H3 text-to-video, image-to-video, and first/last-frame video generation. - [Wan-3.0-API](https://github.com/Anil-matcha/Wan-3.0-API) — Python SDK and MCP server for Wan 3.0-compatible text-to-video, image-to-video, and multimodal reference workflows. - [veo4-video-generator](https://github.com/SamurAIGPT/veo4-video-generator) — Ready-made Next.js SaaS built on Veo 4 - [veo3.1-comfyui](https://github.com/Anil-matcha/veo3.1-comfyui) — Run Veo 3.1 inside ComfyUI - [awesome-ai-video-models](https://github.com/Anil-matcha/awesome-ai-video-models) — compare AI video models by API, price & speed ## 🚀 Why Use Veo 4 API? Veo 4 is Google DeepMind's latest state-of-the-art AI video generation model, featuring a 3x larger Transformer architecture than Veo 3, native 4K output, and advanced character anchoring technology. - **Native 4K Output**: Every pixel generated from scratch — not upscaled. - **Up to 30 Seconds**: Longer clips than any previous Veo model. - **Integrated Audio**: Jointly generates synchronized dialogue, ambient sound, and music in one pass (building on Veo 3's audio breakthrough). - **Character Consistency**: Advanced anchoring technology keeps faces, clothing, and features consistent across all frames and camera angles. - **Advanced Camera Controls**: Pan, zoom, orbit, tracking shots — precise cinematic control. - **Developer-First**: Simple Python SDK via MuAPI infrastructure. ## 🌟 Key Features of Veo 4 API - ✅ **Veo 4 Text-to-Video (T2V)**: Transform descriptive prompts into stunning native 4K video clips up to 30 seconds. - ✅ **Veo 4 Image-to-Video (I2V)**: Animate static images with precise motion and camera control using `images_list`. - ✅ **Integrated Audio-Video Generation**: Jointly generate synchronized audio and video in one pass — include sound cues in your prompt. - ✅ **Character Consistency**: `character_video()` anchors on reference photos to keep identity consistent across scenes. - ✅ **Advanced Camera Controls**: Specify `camera_control` for cinematic movements — pan, zoom, orbit, tracking shots. - ✅ **Video Extension**: Extend existing Veo 4 clips up to 30 seconds total. - ✅ **Video Edit**: Edit existing videos using natural language prompts. - ✅ **File Upload**: Upload local images and videos directly via `upload_file()`. - ✅ **Flexible Aspect Ratios**: Optimized for `16:9`, `9:16` (TikTok/Reels), and `1:1`. - ✅ **Quality Tiers**: `1080p` and `4k` (native) output. --- ## 🛠 Installation ### Via Pip (Recommended) ```bash pip install veo-4-api ``` ### From Source ```bash git clone https://github.com/Anil-matcha/Veo-4-API.git cd Veo-4-API pip install -r requirements.txt ``` ### Configuration Create a `.env` file in the root directory and add your [MuAPI](https://muapi.ai?utm_source=github&utm_medium=readme&utm_campaign=veo-4-api) API key: ```env MUAPI_API_KEY=your_muapi_api_key_here ``` --- ## 🤖 Veo 4 MCP Server Use Veo 4 as an **MCP (Model Context Protocol)** server, allowing AI assistants like Claude Desktop or Cursor to directly invoke Veo 4 generation tools. ### Running the MCP Server 1. Ensure `MUAPI_API_KEY` is set in your environment. 2. Run the server: ```bash python3 mcp_server.py ``` 3. To test with the MCP Inspector: ```bash npx -y @modelcontextprotocol/inspector python3 mcp_server.py ``` --- ## 💻 Quick Start with Veo 4 API (Python) ```python from veo4_api import Veo4API # Initialize the Veo 4 client api = Veo4API() # Generate Video from Text (T2V) print("Generating AI Video using Veo 4...") submission = api.text_to_video( prompt="A cinematic tracking shot through a lush rainforest, sunlight filtering through the canopy, birds calling", aspect_ratio="16:9", duration=8, quality="4k", camera_control="tracking shot" ) # Wait for completion result = api.wait_for_completion(submission['request_id']) print(f"Success! View your Veo 4 video here: {result['outputs'][0]}") ``` --- ## 🎵 Audio-Video Generation Veo 4 jointly generates synchronized video and audio in a single pass — include sound cues in your prompt for best results. ```python from veo4_api import Veo4API api = Veo4API() # Text-to-video with audio submission = api.text_to_video_with_audio( prompt="A street musician playing violin in Paris, rain on cobblestones, distant traffic, melancholic melody", aspect_ratio="16:9", duration=15, quality="4k" ) result = api.wait_for_completion(submission['request_id']) print(f"Video with audio: {result['outputs'][0]}") # Image-to-video with audio submission = api.image_to_video_with_audio( prompt="@image1 comes alive — waves crashing, seagulls calling, ocean breeze rustling palm trees", images_list=["https://example.com/beach.jpg"], duration=10, ) result = api.wait_for_completion(submission['request_id']) print(f"Animated with audio: {result['outputs'][0]}") ``` > **Tip**: Include explicit sound cues (e.g. "thunder rumbling", "crowd cheering", "piano melody") for richer, more accurate audio generation. --- ## 🎭 Character Consistency Veo 4's character anchoring keeps faces and identity consistent across all frames. ```python from veo4_api import Veo4API api = Veo4API() # Anchor on a reference photo submission = api.character_video( prompt="@image1 walks confidently through a neon-lit Tokyo street at night", character_images=["https://example.com/person.jpg"], aspect_ratio="16:9", duration=8, quality="4k", with_audio=True, ) result = api.wait_for_completion(submission['request_id']) print(f"Character video: {result['outputs'][0]}") ``` --- ## 🎬 Camera Controls Specify cinematic camera movements with the `camera_control` parameter. ```python # Zoom in dramatically submission = api.text_to_video( prompt="A lone lighthouse on a rocky cliff at dusk, storm approaching", aspect_ratio="16:9", duration=10, quality="4k", camera_control="slow zoom in" ) # Orbit around a subject submission = api.text_to_video( prompt="A marble statue in a sunlit museum courtyard", aspect_ratio="16:9", duration=8, camera_control="orbit" ) ``` --- ## 📡 API Endpoints & Reference ### 1. Veo 4 Text-to-Video (T2V) **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-t2v` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-t2v" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "prompt": "A majestic eagle soaring over snow-capped mountains at sunrise", "aspect_ratio": "16:9", "duration": 8, "quality": "4k", "camera_control": "pan right" }' ``` ### 2. Veo 4 Image-to-Video (I2V) **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-i2v` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-i2v" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "prompt": "@image1 — the clouds drift slowly, light shifts from golden to dusk", "images_list": ["https://example.com/landscape.jpg"], "aspect_ratio": "16:9", "duration": 8, "quality": "4k" }' ``` ### 3. Veo 4 T2V with Audio **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-t2v-audio` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-t2v-audio" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "prompt": "A busy Tokyo street at night, neon signs, rain, jazz music drifting from a bar", "aspect_ratio": "16:9", "duration": 15, "quality": "4k" }' ``` ### 4. Veo 4 I2V with Audio **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-i2v-audio` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-i2v-audio" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "prompt": "@image1 — waves begin to crash, seagulls cry in the distance, wind howling", "images_list": ["https://example.com/ocean.jpg"], "aspect_ratio": "16:9", "duration": 10, "quality": "4k" }' ``` ### 5. Veo 4 Character Video **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-character` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-character" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "prompt": "@image1 walks confidently through a neon-lit Tokyo street", "images_list": ["https://example.com/person.jpg"], "aspect_ratio": "16:9", "duration": 8, "quality": "4k" }' ``` ### 6. Video Extension **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-extend` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-extend" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "request_id": "your-completed-request-id", "prompt": "The eagle lands on a mountain peak, surveying the valley below", "duration": 10, "quality": "4k" }' ``` ### 7. Video Edit **Endpoint**: `POST https://api.muapi.ai/api/v1/veo-4-video-edit` ```bash curl --location --request POST "https://api.muapi.ai/api/v1/veo-4-video-edit" \ --header "Content-Type: application/json" \ --header "x-api-key: YOUR_API_KEY" \ --data-raw '{ "prompt": "Change the weather to a dramatic thunderstorm", "video_urls": ["https://example.com/video.mp4"], "aspect_ratio": "16:9", "quality": "4k" }' ``` --- ## 📖 API Method Reference | Method | Parameters | Description | | :--- | :--- | :--- | | `text_to_video` | `prompt`, `aspect_ratio`, `duration`, `quality`, `with_audio`, `camera_control` | Generate native 4K video from text. | | `image_to_video` | `prompt`, `images_list`, `aspect_ratio`, `duration`, `quality`, `with_audio`, `camera_control` | Animate images into 4K video. | | `text_to_video_with_audio` | `prompt`, `aspect_ratio`, `duration`, `quality`, `camera_control` | T2V with jointly generated audio. | | `image_to_video_with_audio` | `prompt`, `images_list`, `aspect_ratio`, `duration`, `quality`, `camera_control` | I2V with jointly generated audio. | | `character_video` | `prompt`, `character_images`, `aspect_ratio`, `duration`, `quality`, `with_audio` | Consistent character identity across frames. | | `extend_video` | `request_id`, `prompt`, `duration`, `quality` | Extend an existing Veo 4 video segment. | | `video_edit` | `prompt`, `video_urls`, `images_list`, `aspect_ratio`, `quality` | Edit existing videos with natural language. | | `upload_file` | `file_path` | Upload a local file (image or video) to MuAPI. | | `get_result` | `request_id` | Check task status and retrieve outputs. | | `wait_for_completion` | `request_id`, `poll_interval`, `timeout` | Blocking helper — polls until generation completes. | --- ## 🔗 Official Resources - **API Provider**: [MuAPI.ai](https://muapi.ai?utm_source=github&utm_medium=readme&utm_campaign=veo-4-api) ## 📄 License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. --- **Keywords**: Veo 4 API, Google Veo 4, Google DeepMind Video, AI Video Generator, Text-to-Video AI, Image-to-Video API, Veo 4 Python SDK, Google Video AI, Audio Video Generation, 4K AI Video, Character Consistency AI, Camera Control Video, MuAPI, Video Generation API, Native 4K Video, AI Video Creation, Veo 4 API Documentation, Veo 4 I2V, Veo 4 T2V, Python Video API. - requirements.txt (32 bytes)
requests python-dotenv mcp[cli]
- setup.py (628 bytes)
from setuptools import setup setup( name="veo-4-api", version="0.1.0", author="Anil Matcha", description="A comprehensive Python wrapper for the Veo 4 API by Google DeepMind.", long_description=open("README.md").read(), long_description_content_type="text/markdown", py_modules=["veo4_api", "mcp_server"], install_requires=[ "requests", "python-dotenv", "mcp[cli]" ], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], python_requires='>=3.7', ) - veo4_api.py (11674 bytes)
import os import requests import time from dotenv import load_dotenv # Load environment variables from .env file load_dotenv() class Veo4API: def __init__(self, api_key=None): """ Initialize the Veo 4 API client. :param api_key: Your MuAPI.ai API key. Defaults to MUAPI_API_KEY environment variable. """ self.api_key = api_key or os.getenv("MUAPI_API_KEY") if not self.api_key: raise ValueError("API Key is required. Set MUAPI_API_KEY in .env or pass it to the constructor.") self.base_url = "https://api.muapi.ai/api/v1" self.headers = { "x-api-key": self.api_key, "Content-Type": "application/json" } def text_to_video(self, prompt, aspect_ratio="16:9", duration=8, quality="4k", with_audio=False, camera_control=None): """ Submits a Veo 4 Text-to-Video (T2V) generation task. Veo 4 by Google DeepMind generates native 4K video using an upgraded Transformer architecture (3x parameters vs Veo 3). Supports integrated audio generation and advanced camera controls. :param prompt: The text prompt describing the video. :param aspect_ratio: Video aspect ratio (e.g., '16:9', '9:16', '1:1'). :param duration: Video duration in seconds (8–30). :param quality: Output quality ('1080p' or '4k'). :param with_audio: Whether to jointly generate audio alongside the video. :param camera_control: Optional camera movement hint (e.g., 'pan left', 'zoom in', 'orbit', 'tracking shot'). :return: JSON response with request_id. """ endpoint = f"{self.base_url}/veo-4-t2v" if with_audio: endpoint = f"{self.base_url}/veo-4-t2v-audio" payload = { "prompt": prompt, "aspect_ratio": aspect_ratio, "duration": duration, "quality": quality, } if camera_control: payload["camera_control"] = camera_control return self._post_request(endpoint, payload) def image_to_video(self, prompt, images_list, aspect_ratio="16:9", duration=8, quality="4k", with_audio=False, camera_control=None): """ Submits a Veo 4 Image-to-Video (I2V) generation task. Animate one or more static images into a native 4K video. Reference images in the prompt using @image1, @image2, etc. :param prompt: Text prompt to guide the animation. Use @image1, @image2, etc. :param images_list: A list of image URLs to animate. :param aspect_ratio: Video aspect ratio. :param duration: Video duration in seconds (8–30). :param quality: Output quality ('1080p' or '4k'). :param with_audio: Whether to jointly generate audio alongside the video. :param camera_control: Optional camera movement hint. :return: JSON response with request_id. """ endpoint = f"{self.base_url}/veo-4-i2v" if with_audio: endpoint = f"{self.base_url}/veo-4-i2v-audio" payload = { "prompt": prompt, "images_list": images_list, "aspect_ratio": aspect_ratio, "duration": duration, "quality": quality, } if camera_control: payload["camera_control"] = camera_control return self._post_request(endpoint, payload) def text_to_video_with_audio(self, prompt, aspect_ratio="16:9", duration=8, quality="4k", camera_control=None): """ Generate a Veo 4 video with integrated audio from a text prompt. Veo 4 generates synchronized dialogue, ambient sound, and music jointly in one pass. Include audio cues in the prompt for best results (e.g. 'waves crashing', 'crowd cheering', 'piano melody'). :param prompt: Text prompt. Include audio cues for richer sound. :param aspect_ratio: Video aspect ratio. :param duration: Video duration in seconds (8–30). :param quality: Output quality ('1080p' or '4k'). :param camera_control: Optional camera movement hint. :return: JSON response with request_id. """ return self.text_to_video( prompt, aspect_ratio, duration, quality, with_audio=True, camera_control=camera_control ) def image_to_video_with_audio(self, prompt, images_list, aspect_ratio="16:9", duration=8, quality="4k", camera_control=None): """ Animate images into a Veo 4 video with integrated audio. :param prompt: Text prompt. Reference images with @image1, @image2, etc. Include audio cues for richer output. :param images_list: List of image URLs to animate. :param aspect_ratio: Video aspect ratio. :param duration: Video duration in seconds (8–30). :param quality: Output quality ('1080p' or '4k'). :param camera_control: Optional camera movement hint. :return: JSON response with request_id. """ return self.image_to_video( prompt, images_list, aspect_ratio, duration, quality, with_audio=True, camera_control=camera_control ) def character_video(self, prompt, character_images, aspect_ratio="16:9", duration=8, quality="4k", with_audio=False): """ Generate a video with consistent character identity using Veo 4's character anchoring technology. Veo 4 keeps faces, clothing, and distinguishing features consistent across all frames, even through complex movements and camera changes. :param prompt: Scene description. Reference the character with @image1. :param character_images: List of 1–3 reference image URLs of the character. :param aspect_ratio: Video aspect ratio. :param duration: Video duration in seconds. :param quality: Output quality ('1080p' or '4k'). :param with_audio: Whether to jointly generate audio. :return: JSON response with request_id. Example:: result = api.character_video( prompt="@image1 walks through a futuristic city, confident stride", character_images=["https://example.com/person.jpg"], aspect_ratio="16:9", duration=8, quality="4k", ) video = api.wait_for_completion(result["request_id"]) print(video["outputs"][0]) """ endpoint = f"{self.base_url}/veo-4-character" payload = { "prompt": prompt if "@image1" in prompt else f"@image1 {prompt.strip()}", "images_list": character_images, "aspect_ratio": aspect_ratio, "duration": duration, "quality": quality, "with_audio": with_audio, } return self._post_request(endpoint, payload) def extend_video(self, request_id, prompt="", duration=8, quality="4k"): """ Extends a previously generated Veo 4 video. :param request_id: The request_id of the video segment to extend. :param prompt: Optional text prompt to guide the continuation. :param duration: Seconds to extend by (8–30). :param quality: Output quality ('1080p' or '4k'). :return: JSON response with request_id. """ endpoint = f"{self.base_url}/veo-4-extend" payload = { "request_id": request_id, "prompt": prompt, "duration": duration, "quality": quality, } return self._post_request(endpoint, payload) def video_edit(self, prompt, video_urls, images_list=None, aspect_ratio="16:9", quality="4k"): """ Edit an existing video using natural language with Veo 4. :param prompt: Describe the desired edits. :param video_urls: List of video URLs to edit. :param images_list: Optional list of reference image URLs. :param aspect_ratio: Output video aspect ratio. :param quality: Output quality ('1080p' or '4k'). :return: JSON response with request_id. """ endpoint = f"{self.base_url}/veo-4-video-edit" payload = { "prompt": prompt, "video_urls": video_urls, "images_list": images_list or [], "aspect_ratio": aspect_ratio, "quality": quality, } return self._post_request(endpoint, payload) def _post_request(self, endpoint, payload): response = requests.post(endpoint, json=payload, headers=self.headers) response.raise_for_status() return response.json() def upload_file(self, file_path): """ Uploads a local file (image or video) to MuAPI for use in generation tasks. :param file_path: Path to the local file to upload. :return: JSON response containing the URL of the uploaded file. """ endpoint = f"{self.base_url}/upload_file" headers = {"x-api-key": self.api_key} with open(file_path, "rb") as file_data: files = {"file": file_data} response = requests.post(endpoint, headers=headers, files=files) response.raise_for_status() return response.json() def get_result(self, request_id): """ Polls for the result of a Veo 4 generation task. :param request_id: The request_id returned from a generation call. :return: JSON response with status and outputs. """ endpoint = f"{self.base_url}/predictions/{request_id}/result" response = requests.get(endpoint, headers=self.headers) response.raise_for_status() return response.json() def wait_for_completion(self, request_id, poll_interval=5, timeout=600): """ Blocks until a Veo 4 generation task completes and returns the result. :param request_id: The request_id returned from a generation call. :param poll_interval: Seconds between status polls (default 5). :param timeout: Maximum seconds to wait before raising TimeoutError (default 600). :return: Completed result JSON with 'outputs' list. """ start_time = time.time() while time.time() - start_time < timeout: result = self.get_result(request_id) status = result.get("status") if status == "completed": return result elif status == "failed": raise Exception(f"Video generation failed: {result.get('error')}") print(f"Status: {status}. Waiting {poll_interval} seconds...") time.sleep(poll_interval) raise TimeoutError("Timed out waiting for Veo 4 video generation to complete.") if __name__ == "__main__": try: api = Veo4API() prompt = "A cinematic tracking shot through a lush rainforest, sunlight filtering through the canopy, birds calling" print(f"Submitting T2V task with prompt: {prompt}") submission = api.text_to_video(prompt=prompt, duration=8, quality="4k") request_id = submission.get("request_id") print(f"Task submitted. Request ID: {request_id}") print("Waiting for completion...") result = api.wait_for_completion(request_id) print(f"Generation completed! Video URL: {result.get('outputs', [None])[0]}") except Exception as e: print(f"Error: {e}")