文生图模型接口
本文档介绍了如何使用文生图模型 API 接口。我们提供了 FLUX 和 Stable Diffusion 等高质量的图像生成模型,您可以根据实际需求选择合适的模型。
接口地址
POST https://api.yunyx.top/v1/images/generations
请求参数
| 参数名 | 类型 | 必选 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | FLUX.1-schnell | 模型名称 |
| prompt | string | 是 | - | 提示词 |
| image_size | string | 是 | 1024x1024 | 图像尺寸(部分模型支持) |
| prompt_enhancement | boolean | 否 | false | 提示增强开关(部分模型支持) |
| seed | integer | 否 | - | 随机种子(范围:0-9999999999) |
image_size 可选值
- 1024x1024
- 512x1024
- 768x512
- 768x1024
- 1024x576
- 576x1024
支持的模型
FLUX.1 系列
- FLUX.1-schnell
Stable Diffusion 系列
- stable-diffusion-3-5-large
注意:目前生成的图片 URL 有效期1个小时,请及时做好转存工作,避免因 URL 过期而影响业务。
响应格式
{
"images": [
{
"url": "https://example.com/images/xxx.png"
}
],
"timings": {
"inference": 123
},
"seed": 123
}
注意:生成的图片 URL 中可能包含特殊字符(如 "&" 会被编码为 "\u0026"),这可能导致编码问题。特别是在使用 curl 命令行工具时,建议对 URL 进行适当的解码处理,以确保正确访问图片资源。
示例代码
Python
import requests
url = "https://api.yunyx.top/v1/images/generations"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"model": "FLUX.1-schnell",
"prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats in the background, fish flying over the sea",
"image_size": "1024x1024",
"prompt_enhancement": True
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Node.js
const axios = require('axios');
const url = 'https://api.yunyx.top/v1/images/generations';
const headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
};
const data = {
model: 'FLUX.1-schnell',
prompt: 'an island near sea, with seagulls, moon shining over the sea, light house, boats in the background, fish flying over the sea',
image_size: '1024x1024',
prompt_enhancement: true
};
axios.post(url, data, {headers})
.then(response => console.log(response.data))
.catch(error => console.error(error));
提示词编写建议
- 使用清晰、具体的描述
- 包含重要的细节信息(场景、风格、光照等)
- 使用适当的艺术风格关键词
- 开启 prompt_enhancement 可以获得更好的生成效果
示例提示词
an island near sea, with seagulls, moon shining over the sea, light house, boats in the background, fish flying over the sea
错误码说明
| 错误码 | 说明 |
|---|---|
| 400 | 请求参数错误 |
| 401 | 认证失败 |
| 404 | 模型不存在 |
| 429 | 请求过于频繁 |
| 503 | 服务暂时不可用 |
| 504 | 服务超时 |
注意事项
- 生成的图片 URL 有效期为 1 小时,请及时保存
- 建议开启 prompt_enhancement 获得更好的生成效果(部分模型支持)
- 可以通过设置 seed 参数来固定生成结果
- 请遵守相关法律法规,不要生成违规内容
- 我们会不定期对模型进行更新和调整,包括但不限于模型上下线、价格调整、服务能力调整等
- 如遇到问题,请参考错误码说明或联系客服