# aardio 范例: 火山方舟 AI 文生图、图像编辑

```aardio
//火山方舟 AI 文生图、图像编辑
import console
console.showLoading(" 正在生成图像");

import web.rest.jsonClient;
var http = web.rest.jsonClient();
http.setAuthToken("api_key");

var ark = http.api("https://ark.cn-beijing.volces.com/api/v3");

//发送请求，目标端点: /api/v3/images/generations
var result,err = ark.images.generations({
		"model": "doubao-seedream-4-0-250828",//指定模型 ID
		"prompt": "生成狗狗趴在草地上的近景画面",// 提示词
		"image": "https://ark-project.tos-cn-beijing.volces.com/doc_image/seedream4_imageToimage.png",
		"size": "2K",
		"response_format": "url",
		"watermark": false,
		"sequential_image_generation": "disabled",
		//"stream": true  //启用流式输出(event stream)，参数 2 需要指定 SSE 回调函数
	}
	/*
	,function(eventStream){   
		var data = eventStream.data;
		select(data[["type"]]){
			case "image_generation.partial_succeeded" {
				console.log(data.url) //每次输出一张图像
			}
			case "image_generation.completed" {
				console.dump(data.usage);//已完成
			} 
			else {
				//data 的内容为 ["DONE"]
			}
		} 
	} 
	*/
)

//禁用流式输出则从 result 接收图像，否则 result 为布尔值。
var imageData = result[["data"]] //直接下标操作符（双层方括号）在读取字段失败时返回 null 而不会报错
if(imageData){
	console.log( imageData[1].url )
}
else{
	console.error(err || imageData);
}

console.pause();

/*
附：火山方舟 文档中的 curl 示例：

curl -X POST https://ark.cn-beijing.volces.com/api/v3/images/generations \
	-H "Content-Type: application/json" \
	-H "Authorization: Bearer $ARK_API_KEY" \
	-d '{
	"model": "doubao-seedream-4-0-250828",
	"prompt": "生成狗狗趴在草地上的近景画面",
	"image": "https://ark-project.tos-cn-beijing.volces.com/doc_image/seedream4_imageToimage.png",
	"size": "2K",
	"sequential_image_generation": "disabled",
	"stream": false,
	"response_format": "url",
	"watermark": true
}'
*/

```