Skip to content

Wan 2.7 (image/text/reference → video) API 示例

Wan 2.7 系列支持三类任务:Image-to-Video (wan2.7-i2v)、Text-to-Video (wan2.7-t2v)、Reference-to-Video (wan2.7-r2v)。

-- 创建端点(Agentsflare 网关): POST https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis

查询端点(Agentsflare 网关):

GET https://api.agentsflare.com/alibabacloudapi/v1/tasks/{task_id}

  • 必须包含头:X-DashScope-Async: enable,以及 Authorization: Bearer <API_KEY>

参考原厂文档:详细参数与字段说明请参阅阿里云 Model Studio 文档: https://www.alibabacloud.com/help/en/model-studio/image-to-video-general-api-reference?spm=a2c63.p38356.help-menu-2400256.d_2_3_0.77cc40e5A1aQsq

请求参数(摘要)

参数必填说明
model模型标识:wan2.7-i2v / wan2.7-t2v / wan2.7-r2v
input.prompt条件(t2v 必填)文本提示;t2v 必填,i2v/r2v 可选但推荐
input.media条件媒体列表,包含 { "type": "...", "url": "..." }
input.media.type条件first_frame / reference_image / reference_video(i2v/r2v)
input.media.url条件媒体的公网上可访问 URL
parameters.resolution输出分辨率,如 1080P
parameters.duration生成时长(秒)
parameters.ratio画幅比例,例如 16:9
X-DashScope-Async(请求头)请设置为 enable 以启用异步任务
Authorization(请求头)Bearer <API_KEY>

Image-to-Video(wan2.7-i2v)示例

注意:i2v 的 media 中单图使用 type: "first_frame"(而非简单 image)。下面示例提供 cURL、Python、Node、Go 四种调用方式。

bash
curl -X POST "https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis" \
  -H "Authorization: Bearer $API_KEY" \
  -H "X-DashScope-Async: enable" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.7-i2v",
    "input": {
      "prompt": "A dynamic graffiti character on a rainy night",
      "media": [{ "type": "first_frame", "url": "https://example.com/first-frame.png" }]
    },
    "parameters": { "resolution": "1080P", "duration": 5 }
  }'
python
import requests
import os

API_BASE = 'https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis'
API_KEY = os.getenv('API_KEY')

payload = {
  'model': 'wan2.7-i2v',
  'input': {
    'prompt': 'A dynamic graffiti character on a rainy night',
    'media': [{ 'type': 'first_frame', 'url': 'https://example.com/first-frame.png' }]
  },
  'parameters': { 'resolution': '1080P', 'duration': 5 }
}

headers = {
  'Authorization': f'Bearer {API_KEY}',
  'X-DashScope-Async': 'enable',
  '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/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis';
const API_KEY = process.env.API_KEY;

const payload = {
  model: 'wan2.7-i2v',
  input: {
    prompt: 'A dynamic graffiti character on a rainy night',
    media: [{ type: 'first_frame', url: 'https://example.com/first-frame.png' }]
  },
  parameters: { resolution: '1080P', duration: 5 }
};

(async () => {
  const res = await fetch(API_BASE, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'X-DashScope-Async': 'enable',
      '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 WanI2V {
  public static void main(String[] args) throws Exception {
    String apiBase = "https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis";
    String apiKey = System.getenv("API_KEY");
    String json = "{\"model\":\"wan2.7-i2v\",\"input\":{\"prompt\":\"A dynamic graffiti character on a rainy night\",\"media\":[{\"type\":\"first_frame\",\"url\":\"https://example.com/first-frame.png\"}]},\"parameters\":{\"resolution\":\"1080P\",\"duration\":5}}";

    HttpRequest req = HttpRequest.newBuilder()
      .uri(URI.create(apiBase))
      .header("Authorization", "Bearer " + apiKey)
      .header("X-DashScope-Async", "enable")
      .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());
  }
}

Text-to-Video(wan2.7-t2v)示例

下面示例提供 cURL、Python、Node、Java 四种调用方式。

bash
curl -X POST "https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis" \
  -H "Authorization: Bearer $API_KEY" \
  -H "X-DashScope-Async: enable" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.7-t2v",
    "input": { "prompt": "A kitten runs on the grass at golden hour" },
    "parameters": { "resolution": "1080P", "duration": 5, "ratio": "16:9" }
  }'
python
import requests
import os

API_BASE = 'https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis'
API_KEY = os.getenv('API_KEY')

payload = {
  'model': 'wan2.7-t2v',
  'input': { 'prompt': 'A kitten runs on the grass at golden hour' },
  'parameters': { 'resolution': '1080P', 'duration': 5, 'ratio': '16:9' }
}

headers = {
  'Authorization': f'Bearer {API_KEY}',
  'X-DashScope-Async': 'enable',
  '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/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis';
const API_KEY = process.env.API_KEY;

const payload = {
  model: 'wan2.7-t2v',
  input: { prompt: 'A kitten runs on the grass at golden hour' },
  parameters: { resolution: '1080P', duration: 5, ratio: '16:9' }
};

(async () => {
  const res = await fetch(API_BASE, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'X-DashScope-Async': 'enable',
      '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 WanT2V {
  public static void main(String[] args) throws Exception {
    String apiBase = "https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis";
    String apiKey = System.getenv("API_KEY");
    String json = "{\"model\":\"wan2.7-t2v\",\"input\":{\"prompt\":\"A kitten runs on the grass at golden hour\"},\"parameters\":{\"resolution\":\"1080P\",\"duration\":5,\"ratio\":\"16:9\"}}";

    HttpRequest req = HttpRequest.newBuilder()
      .uri(URI.create(apiBase))
      .header("Authorization", "Bearer " + apiKey)
      .header("X-DashScope-Async", "enable")
      .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());
  }
}

Reference-to-Video(wan2.7-r2v)示例

使用 reference_imagereference_video 标识参考素材,prompt 中引用方式为 "Image 1" / "Video 1"。

下面示例提供 cURL、Python、Node、Java 四种调用方式。

bash
curl -X POST "https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis" \
  -H "Authorization: Bearer $API_KEY" \
  -H "X-DashScope-Async: enable" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.7-r2v",
    "input": {
      "prompt": "Image 1 walks through a garden",
      "media": [{ "type": "reference_image", "url": "https://example.com/ref.png" }]
    },
    "parameters": { "resolution": "1080P", "duration": 5 }
  }'
python
import requests
import os

API_BASE = 'https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis'
API_KEY = os.getenv('API_KEY')

payload = {
  'model': 'wan2.7-r2v',
  'input': {
    'prompt': 'Image 1 walks through a garden',
    'media': [{ 'type': 'reference_image', 'url': 'https://example.com/ref.png' }]
  },
  'parameters': { 'resolution': '1080P', 'duration': 5 }
}

headers = {
  'Authorization': f'Bearer {API_KEY}',
  'X-DashScope-Async': 'enable',
  '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/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis';
const API_KEY = process.env.API_KEY;

const payload = {
  model: 'wan2.7-r2v',
  input: {
    prompt: 'Image 1 walks through a garden',
    media: [{ type: 'reference_image', url: 'https://example.com/ref.png' }]
  },
  parameters: { resolution: '1080P', duration: 5 }
};

(async () => {
  const res = await fetch(API_BASE, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'X-DashScope-Async': 'enable',
      '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 WanR2V {
  public static void main(String[] args) throws Exception {
    String apiBase = "https://api.agentsflare.com/alibabacloudapi/v1/services/aigc/video-generation/video-synthesis";
    String apiKey = System.getenv("API_KEY");
    String json = "{\"model\":\"wan2.7-r2v\",\"input\":{\"prompt\":\"Image 1 walks through a garden\",\"media\":[{\"type\":\"reference_image\",\"url\":\"https://example.com/ref.png\"}]},\"parameters\":{\"resolution\":\"1080P\",\"duration\":5}}";

    HttpRequest req = HttpRequest.newBuilder()
      .uri(URI.create(apiBase))
      .header("Authorization", "Bearer " + apiKey)
      .header("X-DashScope-Async", "enable")
      .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/alibabacloudapi/v1/tasks/<task_id>" \
  -H "Authorization: Bearer $API_KEY"

小贴士

  • Wan2.7 使用 resolution(档位)+ ratio(可选)取代旧版 size
  • task_id 与返回的视频链接有效期为 24 小时,请及时下载保存。

本文档遵循 CC BY-SA 4.0 协议。