curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}'
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": ["https://example.com/ref1.jpg"],
"metadata": {
"resolution": "2K"
}
}'
import requests
response = requests.post(
"https://toapis.com/v1/images/generations",
headers={
"Authorization": "Bearer your-ToAPIs-key",
"Content-Type": "application/json"
},
json={
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}
)
task = response.json()
print(f"任務 ID: {task['id']}")
print(f"狀態: {task['status']}")
import requests
response = requests.post(
"https://toapis.com/v1/images/generations",
headers={
"Authorization": "Bearer your-ToAPIs-key",
"Content-Type": "application/json"
},
json={
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": ["https://example.com/ref1.jpg"],
"metadata": {
"resolution": "2K"
}
}
)
task = response.json()
print(f"任務 ID: {task['id']}")
print(f"狀態: {task['status']}")
const response = await fetch('https://toapis.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-ToAPIs-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'flux-2-flex',
prompt: '一隻可愛的橘貓在窗臺上曬太陽',
size: '1:1',
metadata: {
resolution: '1K'
}
})
});
const task = await response.json();
console.log(`任務 ID: ${task.id}`);
console.log(`狀態: ${task.status}`);
const response = await fetch('https://toapis.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-ToAPIs-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'flux-2-pro',
prompt: '保持角色風格,生成在森林中奔跑的場景',
size: '1:1',
image_urls: ['https://example.com/ref1.jpg'],
metadata: {
resolution: '2K'
}
})
});
const task = await response.json();
console.log(`任務 ID: ${task.id}`);
console.log(`狀態: ${task.status}`);
{
"id": "task_img_abc123def456",
"object": "generation.task",
"model": "flux-2-flex",
"status": "queued",
"progress": 0,
"created_at": 1703884800,
"metadata": {}
}
Flux 2.0
Flux 2.0 圖像生成
使用 Flux 2.0 模型生成高質量圖像,支持文生圖和圖生圖
POST
/
v1
/
images
/
generations
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}'
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": ["https://example.com/ref1.jpg"],
"metadata": {
"resolution": "2K"
}
}'
import requests
response = requests.post(
"https://toapis.com/v1/images/generations",
headers={
"Authorization": "Bearer your-ToAPIs-key",
"Content-Type": "application/json"
},
json={
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}
)
task = response.json()
print(f"任務 ID: {task['id']}")
print(f"狀態: {task['status']}")
import requests
response = requests.post(
"https://toapis.com/v1/images/generations",
headers={
"Authorization": "Bearer your-ToAPIs-key",
"Content-Type": "application/json"
},
json={
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": ["https://example.com/ref1.jpg"],
"metadata": {
"resolution": "2K"
}
}
)
task = response.json()
print(f"任務 ID: {task['id']}")
print(f"狀態: {task['status']}")
const response = await fetch('https://toapis.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-ToAPIs-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'flux-2-flex',
prompt: '一隻可愛的橘貓在窗臺上曬太陽',
size: '1:1',
metadata: {
resolution: '1K'
}
})
});
const task = await response.json();
console.log(`任務 ID: ${task.id}`);
console.log(`狀態: ${task.status}`);
const response = await fetch('https://toapis.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-ToAPIs-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'flux-2-pro',
prompt: '保持角色風格,生成在森林中奔跑的場景',
size: '1:1',
image_urls: ['https://example.com/ref1.jpg'],
metadata: {
resolution: '2K'
}
})
});
const task = await response.json();
console.log(`任務 ID: ${task.id}`);
console.log(`狀態: ${task.status}`);
{
"id": "task_img_abc123def456",
"object": "generation.task",
"model": "flux-2-flex",
"status": "queued",
"progress": 0,
"created_at": 1703884800,
"metadata": {}
}
- Flux 2.0 圖像生成模型
- 通過 model 參數選擇
flux-2-flex(速度較快,適合快速迭代)或flux-2-pro(質量更高,細節更好) - 支持文生圖、圖生圖,最多 8 張參考圖
- 按分辨率計費(1K/2K)
- 異步任務模式,返回
task_id用於查詢結果
重要變更:爲了更好的性能和成本控制,我們不再支持在
image_urls 中直接傳入 base64 圖片數據。請先使用 上傳圖片接口 上傳圖片,獲取 URL 後再調用本接口。Authorizations
string
必填
所有接口均需要使用 Bearer Token 進行認證獲取 API Key:訪問 API Key 管理頁面 獲取您的 API Key使用時在請求頭中添加:
Authorization: Bearer YOUR_API_KEY
Body
string
必填
圖像生成模型名稱可選值:
flux-2-flex- 速度較快,適合快速迭代flux-2-pro- 質量更高,細節更好
string
必填
圖像生成的文本描述
string
預設值:"1:1"
圖像寬高比支持的寬高比:
1:1- 正方形(默認)4:3/3:4- 傳統顯示器比例16:9/9:16- 寬屏/豎屏3:2/2:3- 標準照片
string[]
參考圖像 URL 數組,用於圖生圖⚠️ 僅支持 URL 格式(不支持 base64)
- 公開可訪問的圖片 URL(http:// 或 https://)
- 可使用 上傳圖片接口 上傳本地圖片獲取 URL
- 最多 8 張參考圖
object
元數據參數,用於傳遞額外的配置選項
顯示 支持的 metadata 字段
顯示 支持的 metadata 字段
string
預設值:"1K"
輸出圖像分辨率可選值:
注意: 不同分辨率計費不同,2K 價格高於 1K
1K- 標準分辨率(默認)2K- 高分辨率
| 寬高比 | 1K 尺寸 | 2K 尺寸 |
|---|---|---|
| 1:1 | 1024×1024 | 2048×2048 |
| 4:3 | 1365×1024 | 2730×2048 |
| 3:4 | 1024×1365 | 2048×2730 |
| 16:9 | 1820×1024 | 3640×2048 |
| 9:16 | 1024×1820 | 2048×3640 |
| 3:2 | 1536×1024 | 3072×2048 |
| 2:3 | 1024×1536 | 2048×3072 |
Response
string
任務唯一標識符,用於查詢任務狀態
string
對象類型,固定爲
generation.taskstring
使用的模型名稱
string
任務狀態
queued- 排隊等待處理in_progress- 處理中completed- 成功完成failed- 失敗
integer
任務進度百分比(0-100)
integer
任務創建時間戳(Unix 時間戳)
object
任務元數據
使用場景
場景一:文生圖(快速迭代)
{
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}
場景二:文生圖(高質量輸出)
{
"model": "flux-2-pro",
"prompt": "未來城市的天際線,霓虹燈光,賽博朋克風格,電影質感",
"size": "16:9",
"metadata": {
"resolution": "2K"
}
}
場景三:圖生圖(多參考圖)
{
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": [
"https://example.com/ref1.jpg",
"https://example.com/ref2.jpg"
],
"metadata": {
"resolution": "2K"
}
}
場景四:豎屏海報
{
"model": "flux-2-flex",
"prompt": "音樂會宣傳海報,簡約風格,深色背景",
"size": "9:16",
"metadata": {
"resolution": "1K"
}
}
查詢任務結果圖像生成爲異步任務,提交後會返回任務 ID。使用 獲取圖像任務狀態 接口查詢生成進度和結果。
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}'
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": ["https://example.com/ref1.jpg"],
"metadata": {
"resolution": "2K"
}
}'
import requests
response = requests.post(
"https://toapis.com/v1/images/generations",
headers={
"Authorization": "Bearer your-ToAPIs-key",
"Content-Type": "application/json"
},
json={
"model": "flux-2-flex",
"prompt": "一隻可愛的橘貓在窗臺上曬太陽",
"size": "1:1",
"metadata": {
"resolution": "1K"
}
}
)
task = response.json()
print(f"任務 ID: {task['id']}")
print(f"狀態: {task['status']}")
import requests
response = requests.post(
"https://toapis.com/v1/images/generations",
headers={
"Authorization": "Bearer your-ToAPIs-key",
"Content-Type": "application/json"
},
json={
"model": "flux-2-pro",
"prompt": "保持角色風格,生成在森林中奔跑的場景",
"size": "1:1",
"image_urls": ["https://example.com/ref1.jpg"],
"metadata": {
"resolution": "2K"
}
}
)
task = response.json()
print(f"任務 ID: {task['id']}")
print(f"狀態: {task['status']}")
const response = await fetch('https://toapis.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-ToAPIs-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'flux-2-flex',
prompt: '一隻可愛的橘貓在窗臺上曬太陽',
size: '1:1',
metadata: {
resolution: '1K'
}
})
});
const task = await response.json();
console.log(`任務 ID: ${task.id}`);
console.log(`狀態: ${task.status}`);
const response = await fetch('https://toapis.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-ToAPIs-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'flux-2-pro',
prompt: '保持角色風格,生成在森林中奔跑的場景',
size: '1:1',
image_urls: ['https://example.com/ref1.jpg'],
metadata: {
resolution: '2K'
}
})
});
const task = await response.json();
console.log(`任務 ID: ${task.id}`);
console.log(`狀態: ${task.status}`);
{
"id": "task_img_abc123def456",
"object": "generation.task",
"model": "flux-2-flex",
"status": "queued",
"progress": 0,
"created_at": 1703884800,
"metadata": {}
}
⌘I