### Environment Setup and Execution Commands (Bash) Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Provides commands for setting up the environment, installing dependencies, and running the application. It includes creating a .env file for API keys, installing npm packages, and commands for development, building, and starting the production server. ```bash # Create .env file with your API key echo 'GEMINI_API_KEY="your-gemini-api-key-here"' > .env # Install dependencies npm install # Run development server npm run dev # Build for production npm run build # Start production server npm start ``` -------------------------------- ### Environment Setup Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Instructions for setting up the environment, installing dependencies, and running the application. ```APIDOC ## Environment Setup ### Description Instructions for configuring environment variables, installing dependencies, and running the application. ### 1. Create `.env` file Create a `.env` file in the root directory and add your Gemini API key: ```bash GEMINI_API_KEY="your-gemini-api-key-here" ``` ### 2. Install Dependencies Install project dependencies using npm: ```bash npm install ``` ### 3. Run Development Server Start the development server: ```bash npm run dev ``` ### 4. Build for Production Build the application for production: ```bash npm run build ``` ### 5. Start Production Server Start the production server: ```bash npm start ``` ``` -------------------------------- ### Video Generation Workflow Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Example of a complete workflow for generating and downloading a video using React frontend patterns. ```APIDOC ## Frontend Integration Example ### Description Demonstrates a complete workflow for generating and downloading a video using React frontend patterns. ### Steps 1. **Start video generation**: Send a POST request to `/api/veo/generate` with prompt, model, and aspect ratio. Optionally include an image file. 2. **Poll for completion**: Periodically poll `/api/veo/operation` with the operation name until the operation is done and a video URI is available. 3. **Download the video**: Send a POST request to `/api/veo/download` with the video URI to get the video blob. ### Request Example (Start Video Generation) ```typescript const form = new FormData(); form.append("prompt", prompt); form.append("model", "veo-3.0-generate-001"); form.append("aspectRatio", "16:9"); // if (imageFile) { // form.append("imageFile", imageFile); // } // const startResp = await fetch("/api/veo/generate", { // method: "POST", // body: form, // }); // const { name: operationName } = await startResp.json(); ``` ### Request Example (Poll for Completion) ```typescript // let videoUri: string | null = null; // while (!videoUri) { // await new Promise(resolve => setTimeout(resolve, 5000)); // const pollResp = await fetch("/api/veo/operation", { // method: "POST", // headers: { "Content-Type": "application/json" }, // body: JSON.stringify({ name: operationName }), // }); // const operation = await pollResp.json(); // if (operation.done) { // videoUri = operation.response?.generatedVideos?.[0]?.video?.uri; // } // } ``` ### Request Example (Download Video) ```typescript // const downloadResp = await fetch("/api/veo/download", { // method: "POST", // headers: { "Content-Type": "application/json" }, // body: JSON.stringify({ uri: videoUri }), // }); // const videoBlob = await downloadResp.blob(); // const videoUrl = URL.createObjectURL(videoBlob); // return videoUrl; ``` ``` -------------------------------- ### Complete Video Generation and Download Workflow (TypeScript) Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Demonstrates a complete workflow for generating and downloading a video using React frontend patterns. It includes starting video generation, polling for completion, and downloading the video. This function returns a URL to the downloaded video. ```typescript // Complete video generation workflow async function generateAndDownloadVideo(prompt: string, imageFile?: File) { // Step 1: Start video generation const form = new FormData(); form.append("prompt", prompt); form.append("model", "veo-3.0-generate-001"); form.append("aspectRatio", "16:9"); if (imageFile) { form.append("imageFile", imageFile); } const startResp = await fetch("/api/veo/generate", { method: "POST", body: form, }); const { name: operationName } = await startResp.json(); // Step 2: Poll for completion (every 5 seconds) let videoUri: string | null = null; while (!videoUri) { await new Promise(resolve => setTimeout(resolve, 5000)); const pollResp = await fetch("/api/veo/operation", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: operationName }), }); const operation = await pollResp.json(); if (operation.done) { videoUri = operation.response?.generatedVideos?.[0]?.video?.uri; } } // Step 3: Download the video const downloadResp = await fetch("/api/veo/download", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ uri: videoUri }), }); const videoBlob = await downloadResp.blob(); const videoUrl = URL.createObjectURL(videoBlob); return videoUrl; } // Image generation with model selection async function generateImage(prompt: string, useImagen: boolean = false) { const endpoint = useImagen ? "/api/imagen/generate" : "/api/gemini/generate"; const resp = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt }), }); const { image } = await resp.json(); return `data:${image.mimeType};base64,${image.imageBytes}`; } // Image editing workflow async function editImage(prompt: string, imageDataUrl: string) { const [meta, b64] = imageDataUrl.split(","); const mimeType = meta?.split(";")?.[0]?.replace("data:", "") || "image/png"; const form = new FormData(); form.append("prompt", prompt); form.append("imageBase64", b64); form.append("imageMimeType", mimeType); const resp = await fetch("/api/gemini/edit", { method: "POST", body: form, }); const { image } = await resp.json(); return `data:${image.mimeType};base64,${image.imageBytes}`; } ``` -------------------------------- ### Image Generation and Editing Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt API endpoints for generating images with Gemini or Imagen, and for editing existing images. ```APIDOC ## Image Generation and Editing ### Description Provides endpoints for generating images using Google's Gemini or Imagen models, and for editing existing images based on natural language prompts. ### POST /api/gemini/generate #### Description Generates an image using the Gemini model. #### Method POST #### Endpoint /api/gemini/generate #### Parameters ##### Request Body - **prompt** (string) - Required - The text prompt for image generation. #### Response ##### Success Response (200) - **image** (object) - The generated image details. - **mimeType** (string) - The MIME type of the image. - **imageBytes** (string) - Base64 encoded image data. ### POST /api/imagen/generate #### Description Generates an image using the Imagen model. #### Method POST #### Endpoint /api/imagen/generate #### Parameters ##### Request Body - **prompt** (string) - Required - The text prompt for image generation. #### Response ##### Success Response (200) - **image** (object) - The generated image details. - **mimeType** (string) - The MIME type of the image. - **imageBytes** (string) - Base64 encoded image data. ### POST /api/gemini/edit #### Description Edits an existing image based on a prompt. #### Method POST #### Endpoint /api/gemini/edit #### Parameters ##### Request Body - **prompt** (string) - Required - The text prompt for image editing. - **imageBase64** (string) - Required - Base64 encoded image data of the image to edit. - **imageMimeType** (string) - Required - The MIME type of the image. #### Response ##### Success Response (200) - **image** (object) - The edited image details. - **mimeType** (string) - The MIME type of the image. - **imageBytes** (string) - Base64 encoded image data. ``` -------------------------------- ### Download Generated Video Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Download a generated video using its URI from a completed operation. The API proxies the request to Google's file service with proper authentication. ```APIDOC ## POST /api/veo/download ### Description Downloads a generated video using its URI from a completed operation. ### Method POST ### Endpoint /api/veo/download ### Parameters #### Request Body - **uri** (string) - Required - The URI of the video to download. - **file** (object) - Optional - An object containing the video URI. - **uri** (string) - Required - The URI of the video to download. ### Request Example ```json { "uri": "https://generativelanguage.googleapis.com/v1/files/video-file-id" } ``` ### Response #### Success Response (200) - **Binary video data** (video/mp4) - The video content. - **Content-Disposition** (string) - Inline; filename="veo3_video.mp4" ``` -------------------------------- ### Video Generation with Veo 3 Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Generate videos from text prompts or initial images using Google's Veo 3 model. This is an asynchronous operation that returns an operation name for polling. ```APIDOC ## POST /api/veo/generate ### Description Generate videos from text prompts or initial images using Google's Veo 3 model. This is an asynchronous operation. ### Method POST ### Endpoint /api/veo/generate ### Parameters #### Request Body (Form Data) - **prompt** (string) - Required - The text prompt for video generation. - **model** (string) - Required - The Veo model to use (e.g., "veo-3.0-generate-001"). - **aspectRatio** (string) - Required - The desired aspect ratio (e.g., "16:9"). - **imageFile** (file) - Optional - An initial image file for image-to-video generation. - **imageBase64** (string) - Optional - Base64 encoded initial image data. - **imageMimeType** (string) - Optional - MIME type of the base64 encoded initial image. - **negativePrompt** (string) - Optional - Prompts to exclude from the video generation. ### Request Example (Text-to-video) ```bash curl -X POST http://localhost:3000/api/veo/generate \ -F "prompt=A drone flying over a tropical beach with crystal clear water" \ -F "model=veo-3.0-generate-001" \ -F "aspectRatio=16:9" ``` ### Request Example (Image-to-video) ```bash curl -X POST http://localhost:3000/api/veo/generate \ -F "prompt=Animate this scene with gentle wind blowing through the trees" \ -F "model=veo-3.0-generate-001" \ -F "imageFile=@/path/to/starting-frame.png" \ -F "aspectRatio=16:9" \ -F "negativePrompt=blurry, low quality" ``` ### Response #### Success Response (200) - **name** (string) - The name of the asynchronous operation, used for polling status. #### Response Example ```json { "name": "operations/generate-video-abc123xyz" } ``` ``` -------------------------------- ### Generate Video with Veo 3 Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Generates videos from text prompts or initial images using the Veo 3 model. This is an asynchronous operation initiated via POST requests to the /api/veo/generate endpoint, returning an operation name for status polling. Supports text-to-video, image-to-video, and negative prompts. ```bash # Generate video from text prompt only curl -X POST http://localhost:3000/api/veo/generate \ -F "prompt=A drone flying over a tropical beach with crystal clear water" \ -F "model=veo-3.0-generate-001" \ -F "aspectRatio=16:9" # Generate video from an initial image (image-to-video) curl -X POST http://localhost:3000/api/veo/generate \ -F "prompt=Animate this scene with gentle wind blowing through the trees" \ -F "model=veo-3.0-generate-001" \ -F "imageFile=@/path/to/starting-frame.png" \ -F "aspectRatio=16:9" \ -F "negativePrompt=blurry, low quality" # Generate video using base64 image curl -X POST http://localhost:3000/api/veo/generate \ -F "prompt=Make the water flow and add birds flying" \ -F "model=veo-3.0-generate-001" \ -F "imageBase64=base64_encoded_image_data" \ -F "imageMimeType=image/png" # Response format: # { # "name": "operations/generate-video-abc123xyz" # } ``` -------------------------------- ### Check Video Generation Status Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Poll the status of an ongoing video generation operation. Returns the operation state and video URI when complete. ```APIDOC ## POST /api/veo/operation ### Description Poll the status of an ongoing video generation operation. ### Method POST ### Endpoint /api/veo/operation ### Parameters #### Request Body - **name** (string) - Required - The operation name obtained from the video generation request. ### Request Example ```json { "name": "operations/generate-video-abc123xyz" } ``` ### Response #### Success Response (200) - **done** (boolean) - Indicates if the operation is complete. - **name** (string) - The operation name. - **response** (object) - Present only if `done` is true. Contains the results of the operation. - **generatedVideos** (array) - List of generated videos. - **video** (object) - **uri** (string) - The URI of the generated video. #### Response Example (Still processing) ```json { "done": false, "name": "operations/generate-video-abc123xyz" } ``` #### Response Example (Complete) ```json { "done": true, "name": "operations/generate-video-abc123xyz", "response": { "generatedVideos": [ { "video": { "uri": "https://generativelanguage.googleapis.com/v1/files/video-file-id" } } ] } } ``` ``` -------------------------------- ### Image Editing and Composition with Gemini 2.5 Flash Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Edit existing images or compose multiple images together using text prompts. Supports file uploads, base64 images, and multiple image composition. ```APIDOC ## POST /api/gemini/edit ### Description Edit existing images or compose multiple images together using text prompts. Supports file uploads, base64 images, and multiple image composition. ### Method POST ### Endpoint /api/gemini/edit ### Parameters #### Request Body (Form Data) - **prompt** (string) - Required - The text prompt for editing or composition. - **imageFile** (file) - Optional - The image file to edit. - **imageBase64** (string) - Optional - Base64 encoded image data. - **imageMimeType** (string) - Optional - MIME type of the base64 encoded image. - **imageFiles** (file) - Optional - Multiple image files for composition. ### Request Example (Editing a single image file) ```bash curl -X POST http://localhost:3000/api/gemini/edit \ -F "prompt=Add a rainbow in the sky" \ -F "imageFile=@/path/to/your/image.png" ``` ### Request Example (Editing using base64 image data) ```bash curl -X POST http://localhost:3000/api/gemini/edit \ -F "prompt=Make the background more dramatic" \ -F "imageBase64=base64_encoded_image_data" \ -F "imageMimeType=image/png" ``` ### Request Example (Composing multiple images) ```bash curl -X POST http://localhost:3000/api/gemini/edit \ -F "prompt=Combine these images into a collage with a cohesive style" \ -F "imageFiles=@/path/to/image1.png" \ -F "imageFiles=@/path/to/image2.png" \ -F "imageFiles=@/path/to/image3.png" ``` ### Response #### Success Response (200) - **image** (object) - Contains the generated image data. - **imageBytes** (string) - Base64-encoded image data. - **mimeType** (string) - The MIME type of the image (e.g., "image/png"). #### Response Example ```json { "image": { "imageBytes": "base64_encoded_image_data...", "mimeType": "image/png" } } ``` ``` -------------------------------- ### Generate Image with Imagen 4 Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Generates high-quality images from text prompts using the Imagen 4 model. The API accepts a prompt and an optional model parameter, returning base64-encoded image data. This is a POST request to the /api/imagen/generate endpoint. ```bash # Generate an image with Imagen 4 curl -X POST http://localhost:3000/api/imagen/generate \ -H "Content-Type: application/json" \ -d '{ "prompt": "A serene mountain landscape at sunset with vibrant orange and purple clouds", "model": "imagen-4.0-fast-generate-001" }' # Response format: # { # "image": { # "imageBytes": "base64_encoded_image_data...", # "mimeType": "image/png" # } # } ``` -------------------------------- ### Image Generation with Imagen 4 Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Generate high-quality images from text prompts using Google's Imagen 4 model. The API accepts a prompt and optional model parameter, returning base64-encoded image data. ```APIDOC ## POST /api/imagen/generate ### Description Generate high-quality images from text prompts using Google's Imagen 4 model. ### Method POST ### Endpoint /api/imagen/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt for image generation. - **model** (string) - Optional - The specific Imagen model to use (e.g., "imagen-4.0-fast-generate-001"). ### Request Example ```json { "prompt": "A serene mountain landscape at sunset with vibrant orange and purple clouds", "model": "imagen-4.0-fast-generate-001" } ``` ### Response #### Success Response (200) - **image** (object) - Contains the generated image data. - **imageBytes** (string) - Base64-encoded image data. - **mimeType** (string) - The MIME type of the image (e.g., "image/png"). #### Response Example ```json { "image": { "imageBytes": "base64_encoded_image_data...", "mimeType": "image/png" } } ``` ``` -------------------------------- ### Download Generated Video using URI (Bash) Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Downloads a generated video using its URI from a completed operation. The API proxies the request to Google's file service with proper authentication. It supports two formats for specifying the URI: directly or within a file object. The response is binary video data. ```bash # Download video by URI curl -X POST http://localhost:3000/api/veo/download \ -H "Content-Type: application/json" \ -d '{ "uri": "https://generativelanguage.googleapis.com/v1/files/video-file-id" }' \ --output generated_video.mp4 # Alternative format using file object curl -X POST http://localhost:3000/api/veo/download \ -H "Content-Type: application/json" \ -d '{ "file": { "uri": "https://generativelanguage.googleapis.com/v1/files/video-file-id" } }' \ --output generated_video.mp4 # Response: Binary video data (video/mp4) # Content-Disposition: inline; filename="veo3_video.mp4" ``` -------------------------------- ### Image Generation with Gemini 2.5 Flash Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Generate images using Gemini 2.5 Flash Image model for fast, high-quality results. This endpoint uses Google's multimodal model optimized for image generation. ```APIDOC ## POST /api/gemini/generate ### Description Generate images using Gemini 2.5 Flash Image model for fast, high-quality results. ### Method POST ### Endpoint /api/gemini/generate ### Parameters #### Request Body - **prompt** (string) - Required - The text prompt for image generation. ### Request Example ```json { "prompt": "A futuristic cityscape with flying cars and neon lights" } ``` ### Response #### Success Response (200) - **image** (object) - Contains the generated image data. - **imageBytes** (string) - Base64-encoded image data. - **mimeType** (string) - The MIME type of the image (e.g., "image/png"). #### Response Example ```json { "image": { "imageBytes": "base64_encoded_image_data...", "mimeType": "image/png" } } ``` ``` -------------------------------- ### Generate Image with Gemini 2.5 Flash Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Generates images using the Gemini 2.5 Flash model for fast, high-quality results. This endpoint utilizes Google's multimodal model optimized for image generation. It's a POST request to the /api/gemini/generate endpoint. ```bash # Generate an image with Gemini 2.5 Flash Image curl -X POST http://localhost:3000/api/gemini/generate \ -H "Content-Type: application/json" \ -d '{ "prompt": "A futuristic cityscape with flying cars and neon lights" }' # Response format: # { # "image": { # "imageBytes": "base64_encoded_image_data...", # "mimeType": "image/png" # } # } ``` -------------------------------- ### Edit and Compose Images with Gemini 2.5 Flash Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Edits existing images or composes multiple images using text prompts. This functionality supports file uploads, base64 image data, and multi-image composition via POST requests to the /api/gemini/edit endpoint. ```bash # Edit a single image with a text prompt curl -X POST http://localhost:3000/api/gemini/edit \ -F "prompt=Add a rainbow in the sky" \ -F "imageFile=@/path/to/your/image.png" # Edit using base64 image data curl -X POST http://localhost:3000/api/gemini/edit \ -F "prompt=Make the background more dramatic" \ -F "imageBase64=base64_encoded_image_data" \ -F "imageMimeType=image/png" # Compose multiple images together curl -X POST http://localhost:3000/api/gemini/edit \ -F "prompt=Combine these images into a collage with a cohesive style" \ -F "imageFiles=@/path/to/image1.png" \ -F "imageFiles=@/path/to/image2.png" \ -F "imageFiles=@/path/to/image3.png" # Response format: # { # "image": { # "imageBytes": "base64_encoded_image_data...", # "mimeType": "image/png" # } # } ``` -------------------------------- ### Check Veo 3 Video Generation Status Source: https://context7.com/google-gemini/veo-3-nano-banana-gemini-api-quickstart/llms.txt Polls the status of an ongoing video generation operation initiated by Veo 3. This POST request to the /api/veo/operation endpoint returns the operation state and, upon completion, the video URI. It requires the operation name obtained from the video generation request. ```bash # Check operation status curl -X POST http://localhost:3000/api/veo/operation \ -H "Content-Type: application/json" \ -d '{ "name": "operations/generate-video-abc123xyz" }' # Response when still processing: # { # "done": false, # "name": "operations/generate-video-abc123xyz" # } # Response when complete: # { # "done": true, # "name": "operations/generate-video-abc123xyz", # "response": { # "generatedVideos": [{ # "video": { # "uri": "https://generativelanguage.googleapis.com/v1/files/video-file-id" # } # }] # } # } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.