prompt、scale、width、height。
1. 提交任务
cURL
curl --request POST 'https://api.aichs365.com/api/v1/text_to_image' \
--header 'Content-Type: application/json' \
--header 'X-Legacy-Token: YOUR_ACCESS_TOKEN' \
--data '{
"prompt": "雨后青石巷中的中式茶馆,电影感光影,细节丰富",
"scale": "2.5",
"width": 1024,
"height": 1024
}'
JavaScript
const createResponse = await fetch('https://api.aichs365.com/api/v1/text_to_image', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Legacy-Token': token
},
body: JSON.stringify({
prompt: '雨后青石巷中的中式茶馆,电影感光影,细节丰富',
scale: '2.5',
width: 1024,
height: 1024
})
})
const created = await createResponse.json()
if (!createResponse.ok || !created.success) throw new Error(created.message || '创建任务失败')
const taskId = created.data.task_id
Python
import requests
headers = {"X-Legacy-Token": token}
created_response = requests.post(
"https://api.aichs365.com/api/v1/text_to_image",
headers=headers,
json={
"prompt": "雨后青石巷中的中式茶馆,电影感光影,细节丰富",
"scale": "2.5",
"width": 1024,
"height": 1024,
},
timeout=30,
)
created = created_response.json()
if not created_response.ok or not created.get("success"):
raise RuntimeError(created.get("message", "创建任务失败"))
task_id = created["data"]["task_id"]
创建成功
{
"requestId": "01HZY8QK5W6N7P8R9S0T1U2V3W",
"success": true,
"message": "请求成功",
"code": 200,
"data": {
"task_id": "1900000000000000001",
"status": 0
}
}
2. 查询任务
cURL
curl --get 'https://api.aichs365.com/api/v1/image_generation_query' \
--header 'X-Legacy-Token: YOUR_ACCESS_TOKEN' \
--data-urlencode 'task_id=1900000000000000001'
JavaScript
const query = new URLSearchParams({ task_id: taskId })
const queryResponse = await fetch(`https://api.aichs365.com/api/v1/image_generation_query?${query}`, {
headers: { 'X-Legacy-Token': token }
})
const task = await queryResponse.json()
if (!queryResponse.ok || !task.success) throw new Error(task.message || '查询任务失败')
Python
query_response = requests.get(
"https://api.aichs365.com/api/v1/image_generation_query",
headers=headers,
params={"task_id": task_id},
timeout=30,
)
task = query_response.json()
if not query_response.ok or not task.get("success"):
raise RuntimeError(task.get("message", "查询任务失败"))
生成完成
{
"requestId": "01HZY8QK5W6N7P8R9S0T1U2V3W",
"success": true,
"message": "请求成功",
"code": 200,
"data": {
"resource": "https://cdn.example.com/result.png",
"task_id": "1900000000000000001",
"status": 1,
"error_message": ""
}
}
status=1 时才读取 resource。示例域名和 ID 仅用于说明结构,不代表真实资源。
3. 失败处理
任务失败
{
"requestId": "01HZY8QK5W6N7P8R9S0T1U2V3W",
"success": true,
"message": "请求成功",
"code": 200,
"data": {
"task_id": "1900000000000000001",
"status": -1,
"error_message": "输入内容不符合处理要求"
}
}
data.status。失败后不要继续查询同一任务;根据 error_message 修正输入并创建新任务。