All Products
Search
Document Center

Hologres:Generate images and video with AI Function

Last Updated:Apr 03, 2026

Hologres provides the ai_gen function, which calls large models to generate images and video. Supported capabilities include text-to-image, image editing, multi-image fusion, text-to-video, video generation from first frame, video generation from first and last frames, and reference-based video generation. This topic describes how to use ai_gen to generate images and video.

Prerequisites

  • You have deployed the required image or video generation models in Hologres. For deployment instructions, see AI Model and Deployment. Supported model sources include Model Studio. For more information, see Model Studio Models.

  • To save generated results to OSS, you must have an OSS bucket and configure authorization by using a RAM role.

Function syntax

ai_gen

The basic syntax for the ai_gen function is as follows:

SELECT ai_gen('<model>', <prompt>::TEXT, <file>);

Parameters:

Parameter

Type

Description

model

TEXT

The name of the model deployed in the Hologres console.

prompt

TEXT

A JSON-formatted string that contains the prompt and generation parameters. The prompt parameters vary by scenario. For more information, see the description for each scenario.

file

FILE

The FILE type is used to identify multimodal data (such as images, videos, and audio) and is used only for passing OSS permissions. The model does not directly read this data. You must use the to_file() function to read it.

Return value: A TEXT string in JSON format that contains information such as the URL of the generated result and usage details.

to_file()

A utility function that converts an OSS path to the FILE type for passing OSS access permissions. The syntax is as follows:

to_file('<oss_path>', '<oss_endpoint>', '<role_arn>')

Parameters:

Parameter

Type

Description

oss_path

TEXT

The OSS file path. Example: oss://bucket/path/file.png.

oss_endpoint

TEXT

The internal endpoint of OSS. Example: oss-cn-hangzhou-internal.aliyuncs.com.

role_arn

TEXT

The Alibaba Cloud Resource Name (ARN) of the RAM role used for OSS access. Example: acs:ram::<AccountId>:role/<RoleName>.

Return value: A value of the FILE type. If the file path URL is invalid or the file does not exist, the function returns an error.

Image generation

Text-to-image

Generates images from text descriptions.

Supported models: qwen-image-2.0-pro, qwen-image-2.0-pro-2026-03-03, qwen-image-2.0, qwen-image-2.0-2026-03-03, qwen-image-max, qwen-image-plus, and qwen-image. For more information about how to use these models, see the Model Studio documentation.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

The text description for image generation.

parameters.n

INT

No

The number of images to generate. Default value: 1.

parameters.size

STRING

No

Image dimensions, for example 1024*1024. For supported dimensions, see the model documentation.

parameters.watermark

BOOL

No

Specifies whether to add a watermark.

output_dir

STRING

No

The OSS path where the output results are saved. If you specify this parameter, the system downloads and saves the generated results to your OSS bucket. This action incurs public network traffic fees. Evaluate the cost before using this parameter.

Example 1: Generate an image and preview it without saving to OSS.

-- Generate an image from text, preview it directly without saving it to OSS, and use the deployed qwen-image-2.0-pro model.
SELECT
    ai_gen('qwen_image_2_pro',
    json_build_object(
        'prompt', 'Generate a chibi-style character of Liu Bei',
        'parameters', json_build_object(
            'n', 1,
            'size', '1024*1024',
            'watermark', FALSE
            )
        )::TEXT,
    to_file('oss://xxxx/holo_ai_powered_marketing_content/xxx', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::186xxx:role/xxx')-- Use to_file() for authorization.
    );

The function returns a JSON object with the following structure:

{
  "requestId": "xxx",                -- The request ID.
  "usage": {...},                    -- Image parameters, such as width, height, and count.
  "image_urls": ["https://..."],     -- The public URL of the image returned by Model Studio. This URL is temporary.
  "image_oss_paths": []              -- If no OSS directory is specified, this field is empty.
}

Description of return value fields:

  • requestId: The request ID.

  • usage: Image parameters, including width, height, and count.

  • image_urls: The public URL of the image returned by Model Studio. This URL is temporary.

  • image_oss_paths: This parameter is empty if output_dir is not specified. If output_dir is specified, this parameter returns the path to the file that is saved to OSS.

Example 2: Generate an image and save it to OSS.

-- Generate an image from text and save it to your OSS bucket.
SELECT
    ai_gen('qwen_image_2_pro',
    json_build_object(
        'prompt', 'Generate a chibi-style character of Liu Bei',
        'parameters', json_build_object(
            'n', 1,
            'size', '1024*1024',
            'watermark', FALSE
            ),
        'output_dir', 'oss://xxx/holo_ai_powered_marketing_content/'-- The OSS file path.
        )::TEXT,
    to_file('oss://xxx/holo_ai_powered_marketing_content/xxx', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::186xxx:role/xxx')
    );

After the query runs successfully, you can find the result in the specified OSS directory:

image

Image editing

Edits a reference image based on a text prompt to generate a new image.

Supported models: qwen-image-2.0-pro, qwen-image-edit, qwen-image-edit-plus, and qwen-image-edit-max. For more information, see Image Editing - Qwen.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

The editing description.

reference_urls

STRING[]

Yes

An array of OSS paths for the reference image. This array must contain only one image path.

parameters.n

INT

No

The number of images to generate.

parameters.size

STRING

No

Image dimensions, such as 1024*1024.

parameters.watermark

BOOL

No

Specifies whether to add a watermark.

output_dir

STRING

No

The OSS path to save the output. This action incurs public network traffic fees. Evaluate the cost before using this parameter.

SQL example: Edit an image to generate a new one.

-- Image editing
SELECT ai_gen('qwen_image_edit', json_build_object(
    'prompt', 'Keep the original chibi-style Liu Bei character and Chinese-style comic look. Show Liu Bei riding a tall warhorse as he surveys ahead, calm and commanding. The background blends an ancient city with a futuristic data city, with floating charts, dashboards, blue glowing grids, and streams of information. Liu Bei holds a scroll or token that symbolizes command and decision-making, with a "Hologres" logo on it. Use a grand composition with strong branding and an ad feel that highlights "total control, real-time insight, and strategic planning".',
    'reference_urls', array['oss://xxx/holo_ai_powered_marketing_content/c8403238-3c88-44a6-ac85-2e5447e987b2.png'],
    'parameters', json_build_object(
        'n', 2,
        'size', '1024*1024',
        'watermark', FALSE
    )
)::TEXT, to_file('oss://xxx/holo_ai_powered_marketing_content/xx', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::xxx:role/xxx'));

Example of the generated image:

image

Multi-image fusion

Fuses multiple reference images to generate a new image.

Supported model: qwen-image-2.0-pro.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

The fusion description.

reference_urls

STRING[]

Yes

A list of OSS paths for the reference images.

parameters.n

INT

No

The number of images to generate.

parameters.size

STRING

No

Image size, for example, 1024*1024.

parameters.watermark

BOOL

No

Specifies whether to add a watermark.

output_dir

STRING

No

The OSS path to save the output. This action incurs public network traffic fees. Evaluate the cost before using this parameter.

SQL example: Fuse two images to generate a new image.

SELECT ai_gen('qwen_image_2_pro', json_build_object(
    'prompt', 'Keep the chibi-style Liu Bei character and clothing design from the first image. Place the character in the center holding a "Hologres" scroll. Add a glowing data sigil or blue tech ring under his feet. Gradually reveal a warhorse behind him. Keep Chinese-style clouds, rice paper texture, and an ancient vibe on the left side, and transition to a blue futuristic data city with floating screens, real-time charts, and streams of digital light on the right. Change Liu Bei’s expression from calm to determined to show a sense of mission as he steps into the tech world to promote a real-time data warehouse.',
    'reference_urls', array['oss://hm-ai-hangzhou/holo_ai_powered_marketing_content/c8403238-3c88-44a6-ac85-2e5447e987b2.png', 'oss://hm-ai-hangzhou/holo_ai_powered_marketing_content/bde5d500-5efc-4d77-9651-6d6bd81906fe-1.png'],
    'parameters', json_build_object(
        'n', 1,
        'size', '1024*1024',
        'watermark', FALSE
    )
)::TEXT,
to_file('oss://xxxx/holo_ai_powered_marketing_content/xxx', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::xxxx:role/xxxx')
);

Example of the output:

image

Video generation

Text-to-video

Generates a video from a text description, with an optional background audio track.

Supported model: wan2.6-t2v. For more information, see Video Generation.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

A description of the video content.

audio_url

STRING

No

The OSS path of the background audio.

parameters.size

STRING

No

Video dimensions, such as 1280*720.

parameters.prompt_extend

BOOL

No

Specifies whether to extend the prompt.

parameters.duration

INT

No

The video duration in seconds.

parameters.shot_type

STRING

No

Camera type, such as multi.

output_dir

STRING

No

The OSS path to save the output. This action incurs public network traffic fees. Evaluate the cost before using this parameter.

SQL example: Generate a video from a text description.

-- Text-to-video
select ai_gen('wan26_t2v', json_build_object(
    'prompt', 'A chibi-style Liu Bei rides a horse rapidly from a distance, wearing a golden crown, a blue ancient-style robe, and a red belt, with a determined expression and a leader''s aura. The horse runs with powerful strides, kicking up light dust, and Liu Bei''s clothes flutter, creating a smooth and natural motion. The background features an ancient city gate, auspicious clouds, and morning light, creating a style that combines an epic feel with cartoon cuteness. The camera starts with a long shot to show the whole scene, then quickly zooms in to a medium-close shot to enhance the impact of the character''s entrance, suitable for an opening scene of a short video.',
   -- 'audio_url', 'oss://bucket/path/background.mp3',
    'parameters', json_build_object(
        'size', '1280*720',
        'prompt_extend', TRUE,
        'duration', 5,
        'shot_type', 'multi'
        )
    )::TEXT, 
to_file ('oss://xx/holo_ai_powered_marketing_content/xxx', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::xxx:role/xxx')
);

The function returns a JSON object with the following structure:

{
    "request_id": "...",
    "output": {
        "task_id": "...",
        "task_status": "...",
        "submit_time": "...",
        "scheduled_time": "...",
        "end_time": "...",
        "orig_prompt": "...",
        "video_url": "https://..."
    },
    "usage": {
        "duration": 5,
        "size": "1280*720",
        "input_video_duration": 0,
        "output_video_duration": 5,
        "video_count": 1,
        "SR": 720
    }
}

Example of the final result:

Video generation from first frame

Generates a video from a first-frame image and a text description, with an optional background audio track.

Supported models: wan2.6-i2v-flash and wan2.6-i2v. For more information, see the Model Studio documentation.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

A description of the video content.

img_url

STRING

Yes

The OSS path of the first-frame image.

audio_url

STRING

No

The OSS path of the background audio.

parameters.resolution

STRING

No

Video resolution, such as 720P.

parameters.prompt_extend

BOOL

No

Specifies whether to extend the prompt.

parameters.duration

INT

No

The video duration in seconds.

parameters.shot_type

STRING

No

The shot type, such as multi.

output_dir

STRING

No

The OSS path to save the output. This action incurs public network traffic fees. Evaluate the cost before using this parameter.

SQL example: Generate a video from a first-frame image.

SELECT ai_gen('wan26_i2v', json_build_object(
    'prompt', 'Use this image as the first frame to generate a 5-second character entrance video. A chibi-style Liu Bei on his horse slowly approaches the camera. The character maintains a cute and exquisite Chinese comic style, with his blue costume and red belt swaying slightly, and he holds the "Hologres" scroll steady. The horse moves with natural steps, gently raising its head, its tail and mane swaying in the wind. The surrounding floating data charts and tech screens flash dynamically, blue light effects flow, and the grid on the ground extends forward and glows. The background blends an ancient-style pavilion with a futuristic data city. The camera slowly pushes in, creating a brand IP entrance and a tech ad atmosphere. The video is stable and smooth, with clear details.',
    'img_url', 'oss://xxx/holo_ai_powered_marketing_content/bde5d500-5efc-4d77-9651-6d6bd81906fe-1.png',
    --'audio_url', 'oss://bucket/path/background.mp3',
    'parameters', json_build_object(
        'resolution', '720P',
        'prompt_extend', TRUE,
        'duration', 5,
        'shot_type', 'multi'
    )
)::TEXT,
    to_file('oss://xxx/holo_ai_powered_marketing_content/39dd0230-5260-48b7-98cd-17c2a58b5052-1.png', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::xxx:role/xxx'));

Video generation from first and last frames

Generates a transition video between a first-frame image and a last-frame image.

Supported model: wan2.2-kf2v-flash. For more information, see the Model Studio documentation.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

A description of the video content.

first_frame_url

STRING

Yes

The OSS path of the first-frame image.

last_frame_url

STRING

Yes

The OSS path of the last-frame image.

parameters.resolution

STRING

No

Video resolution, such as 720P.

parameters.prompt_extend

BOOL

No

Specifies whether to extend the prompt.

output_dir

STRING

No

The OSS path to save the output. You must specify a complete file name.

Note

Important: Specifying this directory saves the generated result to your OSS bucket. This action incurs public network traffic fees. Evaluate the cost before using this parameter.

SQL example: Generate a transition video from first and last frame images.

-- Generate a video from first and last frame images.
SELECT ai_gen('wan22_kf2v_flash', json_build_object(
  'prompt', 'Use the first image as the start frame and the second as the end frame to generate a 5-second smooth transition video. A chibi-style Liu Bei is on a horse, holding a "Hologres" scroll, with a background of tech data panels and a blue grid floor. The horse takes small steps, and the character bobs slightly. Subsequently, the tech screens, blue light effects, and city background gradually fade out. The scroll is put away, the horse slowly disappears, and the character lands naturally, transitioning to a standing posture, holding a short cyan blade. The background changes to a simple rice paper and auspicious clouds, smoothly transitioning to the state of the second image. Maintain consistent character costume, crown, chibi-style proportions, and art style. The motion should be natural, the transition seamless, and the camera stable.',
  'first_frame_url', 'oss://xxx/holo_ai_powered_marketing_content/xxx',
  'last_frame_url', 'oss://xxx/holo_ai_powered_marketing_content/yyyy',
  'parameters', json_build_object(
    'resolution', '720P',
    'prompt_extend', TRUE
    -- 'duration', 5
          )
   )::TEXT,
  to_file('oss://hm-ai-xxx/holo_ai_powered_marketing_content/xxx', 'oss-cn-hangzhou-internal.aliyuncs.com', 'acs:ram::xxx:role/xxx'));

Video generation from reference

Generates a video based on one or more reference images, with optional audio and watermarks.

Supported models: wan2.6-r2v-flash and wan2.6-r2v. For more information, see the Model Studio documentation.

prompt parameters:

Field

Type

Required

Description

prompt

STRING

Yes

A description of the video content. You can reference the image paths within the text.

reference_urls

STRING[]

Yes

A list of OSS paths for the reference images.

parameters.size

STRING

No

Video dimensions, such as 1280*720.

parameters.duration

INT

No

The video duration in seconds.

parameters.shot_type

STRING

No

Shot type, such as multi.

parameters.audio

BOOL

是否生成音频。

parameters.watermark

BOOL

是否添加水印。

output_dir

STRING

保存输出结果的 OSS 路径。配置后会产生公网流量费用,请评估成本后使用。

SQL Example: Generate a video based on a reference image.

SELECT ai_gen('wan26_r2v', json_build_object(
  'prompt', 'Merge oss://bucket/path/golden_man.png and oss://bucket/path/stone_man.png into a single image and generate a video of them shaking hands and smiling.',
  'reference_urls', array['oss://bucket/path/golden_man.png', 'oss://bucket/path/stone_man.png'],
  'parameters', json_build_object(
    'size', '1280*720',
    'duration', 5,
    'shot_type', 'multi',
    'audio', TRUE,
    'watermark', FALSE
  ),
  'output_dir', 'oss://bucket/output/'
)::TEXT, to_file('oss://bucket/path/golden_man.png', 'oss-cn-hangzhou-internal.aliyuncs.com', '****role'));

Scenario and model quick reference

Scenario

Supported models

Text-to-image

qwen-image-2.0-pro, qwen-image-2.0-pro-2026-03-03, qwen-image-2.0, qwen-image-2.0-2026-03-03, qwen-image-max, qwen-image-plus, qwen-image

Image editing

qwen-image-2.0-pro, qwen-image-edit, qwen-image-edit-plus, qwen-image-edit-max

Multi-image fusion

qwen-image-2.0-pro

Text-to-video

wan2.6-t2v

Video generation from the first frame

wan2.6-i2v-flash, wan2.6-i2v

Video generation from the first and last frames

wan2.2-kf2v-flash

Reference-based video generation

wan2.6-r2v-flash, wan2.6-r2v

Best practices