Skip to content

Cannot download a generated video by api #1946

@WilliamChen-luckbob

Description

@WilliamChen-luckbob

I’m unable to access Google services directly and have to use a proxy instead.

I’m trying to implement a simple workflow using proxy to generate videos via local calls using the Google Generative AI (google-genai) library.

I’ve been following the steps outlined in the official documentation to verify if the function works properly.

Here is the testing code :

import os
import time

import httpx
from dotenv import load_dotenv
from google import genai
from google.genai import types

if __name__ == '__main__':
    load_dotenv()
    genai_client = genai.Client(
        api_key=os.getenv("GENAI_API_KEY"),
        http_options=types.HttpOptions(
            httpx_client=httpx.Client(proxy=os.getenv("GRPC_PROXY"))

        )
    )
    source = types.GenerateVideosSource(
        prompt="The frame focuses on a hand holding a champagne flute: its lines are sleek and relaxed, adorned with bright red glitter nail polish that boasts a rich luster and distinct fine glitter particles. The transparent tall flute contains half a glass of golden, crystal-clear champagne, with its walls reflecting the surrounding light and the liquid’s surface shimmering with a subtle glow. The background features a blurred cluster of warm yellow vintage light bulbs (appearing as hazy light spots), paired with a dark red curtain. The entire scene is wrapped in soft warm light, exuding a lazy, retro, and exquisite atmosphere.",
        image=types.Image(
            image_bytes=open("test.jpg", "rb").read(),
            mime_type="image/jpg",
        )
    )
    config = types.GenerateVideosConfig(
        duration_seconds=4,
        aspect_ratio="16:9",
        resolution="720p",
        negative_prompt="nsfw",
    )

    operation: types.GenerateVideosOperation = genai_client.models.generate_videos(
        model="veo-3.1-fast-generate-preview",
        source=source,
        config=config
    )

    # Poll the operation status until the video is ready.
    while not operation.done:
        print("Waiting for video generation to complete...")
        time.sleep(10)
        operation = genai_client.operations.get(operation)

    # Download the video.
    video = operation.response.generated_videos[0]
    genai_client.files.download(file=video.video)
    video.video.save("veo3_with_image_input.mp4")
    print("Generated video saved to veo3_with_image_input.mp4")

And here is the result from my breakpoint:
when operation is done, the video seems not generated as expected like below
Image

when running

genai_client.files.download(file=video.video)

it will throw

{APIError}APIError("302 UNKNOWN. {'error': {'code': 302, 'message': 'Unknown Error.', 'status': 'UNKNOWN'}}")

In addition, when I tried to open the video link directly via the page, I received an JSON response as follows:

{
  "error": {
    "code": 403,
    "message": "Generative Language API has not been used in project [xxxxx] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/generativelanguage.googleapis.com/overview?project=[xxxxx] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "SERVICE_DISABLED",
        "domain": "googleapis.com",
        "metadata": {
          "consumer": "projects/[xxxxx]",
          "containerInfo": "[xxxxx]",
          "activationUrl": "https://console.developers.google.com/apis/api/generativelanguage.googleapis.com/overview?project=[xxxxx]",
          "service": "generativelanguage.googleapis.com",
          "serviceTitle": "Generative Language API"
        }
      },
      {
        "@type": "type.googleapis.com/google.rpc.LocalizedMessage",
        "locale": "en-US",
        "message": "Generative Language API has not been used in project [xxxxx] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/generativelanguage.googleapis.com/overview?project=[xxxxx] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."
      },
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developers console API activation",
            "url": "https://console.developers.google.com/apis/api/generativelanguage.googleapis.com/overview?project=[xxxxx]"
          }
        ]
      }
    ]
  }
}

But Generative Language API actually enabled for a month, and this API key is running OK in google ai studio.

The same code functioning well without proxy in my other server. So the problem may due to proxy settings.

I’m not sure what I might have missed.

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.status:awaiting user responsetype: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions