Veo Video Generation API Documentation

Official Gemini Veo asynchronous protocol: submit a video generation task → poll the operation → retrieve the video result

POST/v1beta/models/{model}:predictLongRunning

The Veo model series uses the official Gemini Veo protocol, transparently proxied by the platform. The request body uses instances and parameters. After submission, an operation is returned. Poll it until done=true, then retrieve the result. Refer to the response from List Models for available model names, such as veo-3.1-generate-preview and veo-3.1-fast-generate-preview.

Authorizations

AuthorizationstringRequired

Bearer Token authentication. No Google API Key or GCP credentials are required. Get an API Key: visit the API Key Management Page

Authorization: Bearer YOUR_API_KEY

Submit a Generation Task

POST /v1beta/models/{model}:predictLongRunning

Path parameters:

  • model (required): Veo model name, based on the result returned by the List Models endpoint

The request body uses the official Gemini Veo format:

  • instances (object[], required): Generation input
    • prompt (string, required): Description of the video content, actions, camera shots, style, and audio
    • image (object, optional): First-frame image for image-to-video generation, subject to model support
      • bytesBase64Encoded (string, required): Base64-encoded image content without the Data URL prefix
      • mimeType (string, required): Image MIME type, such as image/png or image/jpeg
  • parameters (object, optional): Generation parameters
    • sampleCount (integer, optional): Number of videos to generate
    • durationSeconds (integer, optional): Video duration in seconds
    • aspectRatio (string, optional): Aspect ratio, such as 16:9 or 9:16
    • resolution (string, optional): Output resolution, such as 720p or 1080p
    • negativePrompt (string, optional): Content that should not appear in the video
    • personGeneration (string, optional): Person generation policy
    • seed (integer, optional): Random seed
    • enhancePrompt (boolean, optional): Whether to enhance the prompt
    • generateAudio (boolean, optional): Whether to generate audio; supported only by models with audio capabilities

Supported parameters and value ranges vary across Veo models. The platform forwards requests according to the official protocol, and the model returns an error for unsupported fields or values.

Text-to-Video Request Example

curl --request POST \  --url https://api.maitoken.net/v1beta/models/veo-3.1-generate-preview:predictLongRunning \  --header 'Authorization: Bearer <token>' \  --header 'Content-Type: application/json' \  --data '{    "instances": [      {        "prompt": "Cinematic aerial shot of ocean waves crashing against reefs at sunset, with the camera slowly moving forward"      }    ],    "parameters": {      "sampleCount": 1,      "durationSeconds": 8,      "aspectRatio": "16:9",      "resolution": "720p",      "generateAudio": true    }  }'

Image-to-Video Request Example

curl --request POST \  --url https://api.maitoken.net/v1beta/models/veo-3.1-generate-preview:predictLongRunning \  --header 'Authorization: Bearer <token>' \  --header 'Content-Type: application/json' \  --data '{    "instances": [      {        "prompt": "Keep the subject consistent, slowly move the camera forward, and have the background clouds flow naturally",        "image": {          "bytesBase64Encoded": "IMAGE_BASE64",          "mimeType": "image/png"        }      }    ],    "parameters": {      "sampleCount": 1,      "durationSeconds": 8,      "aspectRatio": "16:9",      "resolution": "720p"    }  }'

Query Task Status

GET /v1beta/{operation_name}

operation_name must be the complete name from the submission response. Do not replace the model name yourself or use only the task ID.

Processing Response

When done is false, or done=true has not yet been returned, the task is still being processed:

{  "name": "models/veo-3.1-generate-preview/operations/OPERATION_ID",  "done": false}

Successful Response

After the task is complete, done=true, and the generated results are located in response.generateVideoResponse.generatedSamples[]:

{  "name": "models/veo-3.1-generate-preview/operations/OPERATION_ID",  "done": true,  "response": {    "generateVideoResponse": {      "generatedSamples": [        {          "video": {            "uri": "https://api.maitoken.net/v1beta/files/FILE_ID:download?alt=media",            "encoding": "video/mp4"          }        }      ]    }  }}

Depending on the channel configuration, video returns one of the following result formats:

  • uri: Video download URL
  • encodedVideo: Base64-encoded video content
  • encoding: Video MIME type, such as video/mp4

Error Response

If the task fails, done=true, and the error information is located in the top-level error field:

{  "name": "models/veo-3.1-generate-preview/operations/OPERATION_ID",  "done": true,  "error": {    "code": 3,    "message": "Invalid request parameters"  }}

Download the Video

When the result contains video.uri, use the complete returned URL to download the video and include the same API Key used to submit the task:

curl --location \  --url 'VIDEO_URI' \  --header 'Authorization: Bearer <token>' \  --output veo.mp4

When the result contains video.encodedVideo, decode it as standard Base64 content and save it as a video file.

Notes

  • Task queries and file downloads must use the same API Key used to submit the task.
  • Polling every 5–10 seconds is recommended until done=true is returned.
  • Use exponential backoff when encountering 429 or 5xx responses to avoid polling too frequently.
  • A submission request timeout does not mean that task creation failed. Retrying immediately when the submission result is uncertain may create duplicate tasks and incur duplicate charges.
  • After obtaining the operation name, always query the original task instead of resubmitting it while waiting for the result.
  • A client-side timeout does not mean that the server-side task failed. You can continue querying it later using the original operation.
  • Video URLs may expire. Download and store the video promptly after the task succeeds.
  • Explicitly passing durationSeconds, resolution, and generateAudio is recommended instead of relying on implicit defaults that may vary between model versions.
  • Supported durations, aspect ratios, resolutions, audio capabilities, and image-to-video capabilities depend on the models actually available.