开发者资源
Qwen-Image-2512 API 文档
将阿里巴巴的 Qwen-Image-2512 AI 模型集成到您的应用中。通过简单的 REST API 从文本提示生成高质量图片。
1
身份认证
Qwen-Image-2512 API 使用 Bearer Token 认证。在请求头中传递您的 API Key。
身份认证
Authorization: Bearer sk-your-api-key-here
请妥善保管您的 API Key,不要在客户端代码中暴露。
定价
| 类型 | 费用 | 描述 |
|---|---|---|
| 文生图 | 5 积分 | 使用 Qwen-Image-2512 AI 根据文本提示生成图片。 |
2
创建任务
POST
https://qwen-image-2512.org/api/generate异步生成
定价
每次图片生成消耗 5 积分。
发起一个生成任务。API 会立即返回 task_id,您可以用它来轮询获取结果。
请求体参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| prompt | string | 必填 | 图片生成的文本描述。最多 2000 个字符。 |
| size | string | 可选 | 图片尺寸。支持: 1024*1024, 1024*1536, 1536*1024, 768*1024, 1024*768。默认: 1024*1024 |
| seed | number | 可选 | 随机种子,用于生成可复现的结果。-1 表示随机。默认: -1 |
| output_format | string | 可选 | 输出格式: jpeg, png 或 webp。默认: jpeg |
| callback_url | string | 可选 | 任务完成时的 Webhook 回调 URL。 |
请求示例
文生图示例 (cURL)
curl -X POST https://qwen-image-2512.org/api/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A serene mountain landscape at sunset",
"size": "1024*1024",
"output_format": "png"
}'成功响应
{
"code": 200,
"message": "success",
"data": {
"task_id": "n43abc123def456qwenimg",
"status": "IN_PROGRESS"
}
}错误响应
{
"code": 400,
"message": "Bad Request: 'prompt' is required.",
"data": null
}3
查询状态
GET
https://qwen-image-2512.org/api/status轮询此接口以查询任务进度。建议每 5-10 秒轮询一次。
查询参数
| 参数 | 类型 | 描述 |
|---|---|---|
| task_id | string | 从生成接口获取的任务 ID。 必填 |
状态值
PENDING任务排队中IN_PROGRESS处理中SUCCESS已完成FAILED发生错误cURL
curl -X GET "https://qwen-image-2512.org/api/status?task_id=n43abc123def456qwenimg" \
-H "Authorization: Bearer YOUR_API_KEY"响应(处理中)
{
"code": 200,
"message": "success",
"data": {
"task_id": "n43abc123def456qwenimg",
"status": "IN_PROGRESS",
"consumed_credits": 5,
"error_message": null,
"created_at": "2024-12-19T10:00:00Z",
"request": { ... },
"response": null
}
}响应(已完成)
{
"code": 200,
"message": "success",
"data": {
"task_id": "n43abc123def456qwenimg",
"status": "SUCCESS",
"consumed_credits": 5,
"error_message": null,
"created_at": "2024-12-19T10:00:00Z",
"request": { ... },
"response": ["https://cdn.example.com/image.png"]
}
}响应(失败)
{
"code": 200,
"message": "success",
"data": {
"task_id": "n43abc123def456qwenimg",
"status": "FAILED",
"consumed_credits": 0,
"error_message": "Content policy violation detected",
"created_at": "2024-12-19T10:00:00Z",
"request": { ... },
"response": null
}
}错误码
| 状态码 | 描述 |
|---|---|
| 200 | 成功 |
| 400 | 请求错误 - 参数无效(缺少 prompt、尺寸无效等) |
| 401 | 未授权 - API Key 缺失或无效 |
| 404 | 未找到 - 任务 ID 不存在 |
| 500 | 服务器内部错误 - 请重试或联系支持 |