curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-flex",
"prompt": "一只蓝色的猫在草地上",
"resolution": "1K",
"size": "16:9"
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "flux-2-flex",
"prompt": "一只蓝色的猫在草地上",
"resolution": "1K",
"size": "16:9"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "flux-2-flex",
prompt: "一只蓝色的猫在草地上",
resolution: "1K",
size: "16:9"
};
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
{
"error": {
"code": 400,
"message": "请求参数无效",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 401,
"message": "身份验证失败,请检查您的API密钥",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "账户余额不足,请充值后再试",
"type": "payment_required"
}
}
Flux 2.0 图像生成
- 异步处理模式,返回任务ID用于后续查询
- 支持文本转图片、图生图等多种生成模式
- 生成的图像链接,有效期为24小时,请尽快保存
POST
/
v1
/
images
/
generations
curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-flex",
"prompt": "一只蓝色的猫在草地上",
"resolution": "1K",
"size": "16:9"
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "flux-2-flex",
"prompt": "一只蓝色的猫在草地上",
"resolution": "1K",
"size": "16:9"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "flux-2-flex",
prompt: "一只蓝色的猫在草地上",
resolution: "1K",
size: "16:9"
};
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
{
"error": {
"code": 400,
"message": "请求参数无效",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 401,
"message": "身份验证失败,请检查您的API密钥",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "账户余额不足,请充值后再试",
"type": "payment_required"
}
}
curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-flex",
"prompt": "一只蓝色的猫在草地上",
"resolution": "1K",
"size": "16:9"
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "flux-2-flex",
"prompt": "一只蓝色的猫在草地上",
"resolution": "1K",
"size": "16:9"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "flux-2-flex",
prompt: "一只蓝色的猫在草地上",
resolution: "1K",
size: "16:9"
};
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
{
"error": {
"code": 400,
"message": "请求参数无效",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 401,
"message": "身份验证失败,请检查您的API密钥",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "账户余额不足,请充值后再试",
"type": "payment_required"
}
}
支持的模型
| 模型名 | 说明 | 计费方式 |
|---|---|---|
flux-2-flex | Flux 2.0 Flex 图片生成模型(速度较快,适合快速迭代) | 按分辨率计费 (1K/2K) |
flux-2-pro | Flux 2.0 Pro 图片生成模型(质量更高,细节更好) | 按分辨率计费 (1K/2K) |
Authorizations
所有接口均需要使用Bearer Token进行认证获取 API Key:访问 API Key 管理页面 获取您的 API Key使用时在请求头中添加:
Authorization: Bearer YOUR_API_KEY
Body
模型名称
flux-2-flex- Flux 2.0 Flex 模型(速度较快,适合快速迭代)flux-2-pro- Flux 2.0 Pro 模型(质量更高,细节更好)
图像生成的文本描述
图像分辨率支持的分辨率:
1K- 默认,1080p 级别2K- 高清,最大 2048 像素
支持大小写:1k、1K、2k、2K均可
图像宽高比支持的宽高比:
1:1- 方形(默认)4:3- 横向3:4- 纵向16:9- 宽屏9:16- 竖屏3:2- 经典横向2:3- 经典纵向
仅支持以上 7 种比例,传入不支持的比例会返回错误
参考图像的 URL 列表限制:
- 最多 8 张图片
- 必须是公网可访问的 URL
- 不支持 base64 格式
分辨率对照表
| 比例 | 名称 | 1K 尺寸 | 2K 尺寸 |
|---|---|---|---|
1:1 | 方形 | 1440×1440 | 1536×1536 |
4:3 | 横向 | 1664×1248 | 1824×1368 |
3:4 | 纵向 | 1248×1664 | 1368×1824 |
16:9 | 宽屏 | 1920×1080 | 2048×1152 |
9:16 | 竖屏 | 1080×1920 | 1152×2048 |
3:2 | 经典横向 | 1728×1152 | 1872×1248 |
2:3 | 经典纵向 | 1152×1728 | 1248×1872 |
使用场景示例
基础文生图{
"model": "flux-2-flex",
"prompt": "一只蓝色的猫",
"resolution": "1K",
"size": "16:9"
}
{
"model": "flux-2-pro",
"prompt": "精细的风景画,山川河流",
"resolution": "2K",
"size": "16:9"
}
{
"model": "flux-2-flex",
"prompt": "将图片转换为水彩画风格",
"image_urls": [
"https://example.com/input1.jpg",
"https://example.com/input2.jpg"
],
"resolution": "1K"
}
Response
响应状态码
注意事项
- 图片 URL 要求:输入图片必须是公网可访问的 URL,不支持 base64
- 结果存储:生成的图片会自动存储,返回的 URL 有效期 24 小时
- 任务轮询:任务为异步处理,需要轮询
/v1/tasks/{task_id}获取结果 - 输入图片限制:最多支持 8 张参考图片
⌘I