快速开始
欢迎使用悠船开放平台!本指南将帮助您快速开始使用我们的图像生成开放平台。
1. 获取开放平台密钥
首先,您需要在悠船控制台注册并获取您的开放平台密钥。
x-youchuan-app:机构标识x-youchuan-secret:机构授权码
2. 创建第一个请求
使用以下代码示例生成您的第一张图像:
import requests
url = "https://ali.youchuan.cn/v1/tob/diffusion"
headers = {
"x-youchuan-app": "YOUR_APP_ID",
"x-youchuan-secret": "YOUR_SECRET_KEY"
}
data = {
"text": "A beautiful sunset over the mountains",
"callback": ""
}
response = requests.post(url, headers=headers, json=data)
print(response.json())# 任务结果json示例
{
"id": "68be9b50553a97d658968285", // 任务ID
"text": "A beautiful sunset over the mountains", // 提示词
"urls": [], // 任务生成图片链接
"status": 1, // 任务状态,执行中(1)/成功(2)/失败(3)
"comment": "执行中", // 任务状态具体说明
"cost": {
"jobId": "68be9b50553a97d658968285",
"fastCost": 1, // 计费系数
"relaxCost": 0, // 暂不开放
"feeCost": 50, // 任务费用(计费系数 x 标准任务单价)
"costAt": "2025-09-08T09:01:04.510389204Z"
},
"audits": [], // 图片审核状态,空为正常(与urls按数组位置对应)
"seed": 0 // 任务seed值
}3. 处理回调
当图像生成完成后,我们会向您指定的回调URL发送通知:
@app.route('/callback', methods=['POST'])
def handle_callback():
data = request.json
# 处理生成的图像
image_url = data['urls']
# ... 其他处理逻辑
return 'OK'# 通知结果示例
# 任务结果json示例
{
"id": "68be9b50553a97d658968285",
"text": "A beautiful sunset over the mountains",
"urls": [
"https://youchuan.oss-cn-shanghai.aliyuncs.com/xxxxx_1.png",
"https://youchuan.oss-cn-shanghai.aliyuncs.com/xxxxx_2.png",
"",
"https://youchuan.oss-cn-shanghai.aliyuncs.com/xxxxx_4.png",
],
"status": 2,
"comment": "成功",
"cost": {
"jobId": "68be9b50553a97d658968285",
"fastCost": 1,
"relaxCost": 0,
"feeCost": 50,
"costAt": "2025-09-08T09:01:04.510743Z"
},
"audits": [
"",
"",
"涉政",
""
],
"seed": 4291795396
}提示: 您也可以通过 任务查询接口 获取任务状态和结果
4. 探索更多功能
下一步
如有任何问题,请随时联系我们的支持团队。祝您使用愉快!