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
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_KEYSubmit a Generation Task
POST /v1beta/models/{model}:predictLongRunningPath 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 inputprompt(string, required): Description of the video content, actions, camera shots, style, and audioimage(object, optional): First-frame image for image-to-video generation, subject to model supportbytesBase64Encoded(string, required): Base64-encoded image content without the Data URL prefixmimeType(string, required): Image MIME type, such asimage/pngorimage/jpeg
parameters(object, optional): Generation parameterssampleCount(integer, optional): Number of videos to generatedurationSeconds(integer, optional): Video duration in secondsaspectRatio(string, optional): Aspect ratio, such as16:9or9:16resolution(string, optional): Output resolution, such as720por1080pnegativePrompt(string, optional): Content that should not appear in the videopersonGeneration(string, optional): Person generation policyseed(integer, optional): Random seedenhancePrompt(boolean, optional): Whether to enhance the promptgenerateAudio(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 URLencodedVideo: Base64-encoded video contentencoding: Video MIME type, such asvideo/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.mp4When 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=trueis returned. - Use exponential backoff when encountering
429or5xxresponses 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, andgenerateAudiois 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.
