Recently Google made its Veo video generation tool available through its Vertex API, which means that is it now possible to encapsulate this functionality into the Wolfram Language. I hope and expect this this will becoming part of the Wolfram Language in 2025, but if you are like me and can’t wait here is a way to connect to this API today. You will need your own Google Cloud account to be able to get this to work, but this notebook will take you through the steps to get this up and running for you. Once you’re configured you too should be able to make short 8 second videos of guinea pigs!

Prerequisites

◼
  • Google Cloud account with a project (you will need the project id) that has the Vertex API enabled. None of the functionality described below this point will work without this.
  • Set up requirements

    You need to install the gcloud command line tool for authentication. This opens the web page that documents how to do this:
    In[]:=
    SystemOpen["https://cloud.google.com/sdk/docs/install"]
    After installation you need to run the following command from a terminal to authenticate against Google Cloud (this is an interactive process that includes opening a web browser):
    > gcloud auth login
    Once installed on your machine you need to set an environment variable to help the Wolfram Language find the SDK. In my case the SDK is installed under my home directory:
    In[]:=
    SetEnvironment["GCLOUD_SDK_HOME"->"/Users/arnoudb/google-cloud-sdk"];
    The API authentication tokens change over time and expire every couple of minutes. This gets a fresh authentication token every time:
    In[]:=
    $GeminiAuthToken:=StringTrim[RunProcess[{FileNameJoin[{Environment["GCLOUD_SDK_HOME"],"bin","gcloud"}],"auth","print-access-token"},"StandardOutput"]];
    Set up the remaining environment variables. You will need to specify your own project id here
    In[]:=
    SystemCredential["GOOGLE_PROJECT_ID"]="canvas-modem-386317";(*changethistoyourownGoogleprojectid*)
    In[]:=
    SetEnvironment["GOOGLE_LOCATION"->"us-central1"];(*changethistothelocationthatmakesthemostsensetoyourgeolocation*)​​SetEnvironment["GEMINI_BASE_URL"->"https://"<>Environment["GOOGLE_LOCATION"]<>"-aiplatform.googleapis.com/v1/"];SetEnvironment["GOOGLE_PROJECT_ID"->SystemCredential["GOOGLE_PROJECT_ID"]];(*thiscredentialshouldpointtoyourGoogleprojectid*)​​SetEnvironment["GOOGLE_MODEL"->"veo-2.0-generate-001"];(*thisisthevideogenerationmodelname*)​​
    The following VideoSynthesize function does all the work of generating a short video from a prompt. It builds the API request, submits it, and then loops until the computation is complete and the generated video can be downloaded from another API end point. It saves the video to your machine as “out-<date>.mp4” and also opens it in your default video player. Finally it returns the Video object:
    In[]:=
    VideoSynthesize[prompt_String]:=Module{generateUrl,generateJson,generateRequest,generateResponse,resultLocation,retrieveResultUrl,retrieveJson,retrieveRequest,retrieveResponse,retrieveAssociation,done,bytes,filename},​​generateUrl=URLBuild
    <>":predictLongRunning";​​generateJson="instances"{"prompt"prompt},"parameters""aspectRatio""16:9","personGeneration""allow";​​generateRequest=HTTPRequestgenerateUrl,
    ;​​generateResponse=URLRead[generateRequest];​​resultLocation=ImportByteArray[generateResponse["BodyByteArray"],"RawJSON"];​​retrieveResultUrl=URLBuild
    <>":fetchPredictOperation";​​retrieveJson=<|"operationName"->resultLocation["name"]|>;​​done=False;​​PrintTemporary[ProgressIndicator[Appearance->"Percolate"]];​​While​​Not[done],​​Pause[1];​​retrieveRequest=HTTPRequestretrieveResultUrl,
    ​​;​​retrieveResponse=URLRead[retrieveRequest];​​retrieveAssociation=ImportByteArray[retrieveResponse["BodyByteArray"],"RawJSON"];​​If[KeyExistsQ[retrieveAssociation,"done"]&&retrieveAssociation["done"]===True,done=True]​​;​​bytes=ImportString[retrieveAssociation["response"]["videos"][[1]]["bytesBase64Encoded"],{"Base64","Byte"}];​​filename="out-"<>DateString["ISODateTime"]<>".mp4";​​Export[filename,ByteArray[bytes],"Byte"];​​SystemOpen[filename];​​Import[filename]​​

    Here are some examples!

    In[]:=
    VideoSynthesize["Three guinea pigs walking through a living room"]
    Out[]=
    In[]:=
    VideoSynthesize["A yellow lab chasing a ball in a park"]
    Out[]=
    In[]:=
    VideoSynthesize["A cat chasing a laser pointer"]
    Out[]=

    CITE THIS NOTEBOOK

    Creating short artificial videos with the Wolfram Language​
    by Arnoud Buzing​
    Wolfram Community, STAFF PICKS, April 24, 2025
    ​https://community.wolfram.com/groups/-/m/t/3450620