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 |
| TEXT | The name of the model deployed in the Hologres console. |
| 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 | 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 |
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 |
| TEXT | The OSS file path. Example: |
| TEXT | The internal endpoint of OSS. Example: |
| TEXT | The Alibaba Cloud Resource Name (ARN) of the RAM role used for OSS access. Example: |
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 |
| STRING | Yes | The text description for image generation. |
| INT | No | The number of images to generate. Default value: 1. |
| STRING | No | Image dimensions, for example |
| BOOL | No | Specifies whether to add a watermark. |
| 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 ifoutput_diris not specified. Ifoutput_diris 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 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 |
| STRING | Yes | The editing description. |
| STRING[] | Yes | An array of OSS paths for the reference image. This array must contain only one image path. |
| INT | No | The number of images to generate. |
| STRING | No | Image dimensions, such as |
| BOOL | No | Specifies whether to add a watermark. |
| 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:

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 |
| STRING | Yes | The fusion description. |
| STRING[] | Yes | A list of OSS paths for the reference images. |
| INT | No | The number of images to generate. |
| STRING | No | Image size, for example, |
| BOOL | No | Specifies whether to add a watermark. |
| 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:

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 |
| STRING | Yes | A description of the video content. |
| STRING | No | The OSS path of the background audio. |
| STRING | No | Video dimensions, such as |
| BOOL | No | Specifies whether to extend the prompt. |
| INT | No | The video duration in seconds. |
| STRING | No | Camera type, such as |
| 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 |
| STRING | Yes | A description of the video content. |
| STRING | Yes | The OSS path of the first-frame image. |
| STRING | No | The OSS path of the background audio. |
| STRING | No | Video resolution, such as |
| BOOL | No | Specifies whether to extend the prompt. |
| INT | No | The video duration in seconds. |
| STRING | No | The shot type, such as |
| 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 |
| STRING | Yes | A description of the video content. |
| STRING | Yes | The OSS path of the first-frame image. |
| STRING | Yes | The OSS path of the last-frame image. |
| STRING | No | Video resolution, such as |
| BOOL | No | Specifies whether to extend the prompt. |
| 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 |
| STRING | Yes | A description of the video content. You can reference the image paths within the text. |
| STRING[] | Yes | A list of OSS paths for the reference images. |
| STRING | No | Video dimensions, such as |
| INT | No | The video duration in seconds. |
| STRING | No | Shot type, such as |
| BOOL | 否 | 是否生成音频。 |
| BOOL | 否 | 是否添加水印。 |
| 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 |
|
Image editing |
|
Multi-image fusion |
|
Text-to-video |
|
Video generation from the first frame |
|
Video generation from the first and last frames |
|
Reference-based video generation |
|
Best practices
Best practices: Game ad video generation using AI Function