Vidu API 示例
Vidu 系列(例如 Vidu Q3)通过 Agentsflare 网关提供视频生成能力,通常使用通用异步接口:
-- 创建端点:POST https://api.agentsflare.com/v1/videos/generations -- 查询端点:GET https://api.agentsflare.com/v1/async-result/{task_id}
- 认证:
Authorization: Bearer <API_KEY>
参考原厂文档:Vidu 详细说明(原厂): https://zhipu-ai.feishu.cn/wiki/NSH1wPKppiVgsUkeqdccBo0qnAG
请求参数(摘要)
| 参数 | 必填 | 说明 |
|---|---|---|
model | 是 | 例如 viduq3-turbo-text2video / viduq3-pro-img2video |
prompt | 是 | 文本提示,描述主体与动作 |
duration | 是 | 视频时长(秒),常用 5 |
movement_amplitude | 否 | 运动幅度,例如 low / medium / high |
with_audio | 否 | 是否生成音频,true / false |
first_frame_image | 条件 | 单图输入的首帧 URL(图生视频场景) |
resolution | 否 | 输出分辨率 |
aspect_ratio | 否 | 画幅比,例如 16:9 |
callback_url | 否 | 异步回调 URL |
external_task_id | 否 | 业务自定义任务 ID |
文生视频(Text to Video)示例
单图生视频(Image to Video)示例
bash
curl -X POST "https://api.agentsflare.com/v1/videos/generations" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "viduq3-pro-img2video",
"prompt": "The man on the left has white light flashing in his glasses",
"duration": 5,
"first_frame_image": "https://example.com/first.png"
}'python
import requests
import os
API_BASE = 'https://api.agentsflare.com/v1/videos/generations'
API_KEY = os.getenv('API_KEY')
payload = {
'model': 'viduq3-pro-img2video',
'prompt': 'The man on the left has white light flashing in his glasses',
'duration': 5,
'first_frame_image': 'https://example.com/first.png'
}
headers = {'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'}
resp = requests.post(API_BASE, json=payload, headers=headers)
print(resp.status_code)
print(resp.text)javascript
const fetch = require('node-fetch');
const API_BASE = 'https://api.agentsflare.com/v1/videos/generations';
const API_KEY = process.env.API_KEY;
const payload = {
model: 'viduq3-pro-img2video',
prompt: 'The man on the left has white light flashing in his glasses',
duration: 5,
first_frame_image: 'https://example.com/first.png'
};
(async () => {
const res = await fetch(API_BASE, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
console.log(await res.text());
})();java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ViduImage2V {
public static void main(String[] args) throws Exception {
String apiBase = "https://api.agentsflare.com/v1/videos/generations";
String apiKey = System.getenv("API_KEY");
String json = "{\"model\":\"viduq3-pro-img2video\",\"prompt\":\"The man on the left has white light flashing in his glasses\",\"duration\":5,\"first_frame_image\":\"https://example.com/first.png\"}";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(apiBase))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.statusCode());
System.out.println(resp.body());
}
}查询任务示例
bash
curl -X GET "https://api.agentsflare.com/v1/async-result/<task_id>" \
-H "Authorization: Bearer $API_KEY"支持的模型
以下模型可通过本接口调用(按推荐程度排序):
viduq3-pro-img2videoNewviduq3-turbo-text2videoNewviduq3-pro-text2videoNewviduq3-turbo-img2videoNewviduq3-turbo-img2video-frameNewviduq3-pro-img2video-frameNew
💡 提示
请求示例中的 model 字段可替换为上方任意模型名称。
bash
curl -X POST "https://api.agentsflare.com/v1/videos/generations" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "viduq3-turbo-text2video",
"prompt": "A silver spaceship glides above the sea at sunrise, cinematic light",
"duration": 5,
"movement_amplitude": "medium",
"with_audio": true
}'python
import requests
import os
API_BASE = 'https://api.agentsflare.com/v1/videos/generations'
API_KEY = os.getenv('API_KEY')
payload = {
'model': 'viduq3-turbo-text2video',
'prompt': 'A silver spaceship glides above the sea at sunrise, cinematic light',
'duration': 5,
'movement_amplitude': 'medium',
'with_audio': True
}
headers = {'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'}
resp = requests.post(API_BASE, json=payload, headers=headers)
print(resp.status_code)
print(resp.text)javascript
const fetch = require('node-fetch');
const API_BASE = 'https://api.agentsflare.com/v1/videos/generations';
const API_KEY = process.env.API_KEY;
const payload = {
model: 'viduq3-turbo-text2video',
prompt: 'A silver spaceship glides above the sea at sunrise, cinematic light',
duration: 5,
movement_amplitude: 'medium',
with_audio: true
};
(async () => {
const res = await fetch(API_BASE, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
console.log(await res.text());
})();java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ViduText2V {
public static void main(String[] args) throws Exception {
String apiBase = "https://api.agentsflare.com/v1/videos/generations";
String apiKey = System.getenv("API_KEY");
String json = "{\"model\":\"viduq3-turbo-text2video\",\"prompt\":\"A silver spaceship glides above the sea at sunrise, cinematic light\",\"duration\":5,\"movement_amplitude\":\"medium\",\"with_audio\":true}";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(apiBase))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.statusCode());
System.out.println(resp.body());
}
}:::