外观
FLUX.2
FLUX.2 是 Black Forest Labs 在 Pixapi 上按分辨率计费的图片系列。选择 flux-2-pro、flux-2-max 或 flux-2-flex,再通过 resolution 传入 1MP、2MP、3MP 或 4MP。
API 形式
| 操作 | Endpoint | 模式 |
|---|---|---|
| 图片生成 | POST /v1/images/generations | 同步 |
| 图片生成任务 | POST /v1/async/images/generations | 异步 |
| 图片编辑 | POST /v1/images/edits | 同步 |
| 图片编辑任务 | POST /v1/async/images/edits | 异步 |
模型 id
| 模型 id | 适合 |
|---|---|
flux-2-pro | 平衡画质与积分成本的 FLUX.2 |
flux-2-max | 更高规格的 FLUX.2 输出 |
flux-2-flex | 灵活的 FLUX.2 分辨率档位 |
价格
| 模型 id | 1MP | 2MP | 3MP | 4MP |
|---|---|---|---|---|
flux-2-pro | 3 | 4 | 5 | 6 |
flux-2-max | 6 | 8 | 10 | 13 |
flux-2-flex | 4 | 8 | 12 | 16 |
如果省略 resolution,按 1MP 档计费。
请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 使用 flux-2-pro、flux-2-max 或 flux-2-flex。模型 ID 区分大小写。 |
prompt | string | 是 | 提示词,最长 2,000 字符。 |
image | string | string[] | 编辑时必填 | 公网图片 URL,或 URL 数组。 |
n | integer | 否 | 输出数量,默认 1,最大 9。 |
size | string | 否 | 上游支持的输出尺寸,将按原值透传。 |
quality | string | 否 | 可选的上游质量参数。 |
output_format | string | 否 | 上游支持时可传 png 等输出格式。 |
resolution | string | 否 | 1MP(默认)、2MP、3MP 或 4MP,同时决定输出档位和计费。 |
providerOptions | object | 否 | 其他供应商扩展字段。 |
示例
bash
curl https://api.pixapi.ai/v1/images/generations \
-H "Authorization: Bearer $PIXAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"flux-2-pro","prompt":"暖灰背景上的简洁杂志风产品照片","n":1,"resolution":"2MP"}'py
import os
import requests
response = requests.post(
"https://api.pixapi.ai/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ['PIXAPI_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "flux-2-pro",
"prompt": "暖灰背景上的简洁杂志风产品照片",
"n": 1,
"resolution": "2MP"
},
)
response.raise_for_status()
print(response.json())js
const response = await fetch('https://api.pixapi.ai/v1/images/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PIXAPI_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"model": "flux-2-pro",
"prompt": "暖灰背景上的简洁杂志风产品照片",
"n": 1,
"resolution": "2MP"
}),
});
if (!response.ok) {
throw new Error(await response.text());
}
console.log(await response.json());go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
body := []byte(`{
"model": "flux-2-pro",
"prompt": "暖灰背景上的简洁杂志风产品照片",
"n": 1,
"resolution": "2MP"
}`)
req, err := http.NewRequest(
"POST",
"https://api.pixapi.ai/v1/images/generations",
bytes.NewBuffer(body),
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("PIXAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}编辑图片
json
{
"model": "flux-2-pro",
"prompt": "把背景替换为极简摄影棚",
"image": "https://example.com/input.png",
"n": 1
}异步请求与任务轮询请参阅异步媒体任务。
统一响应结构见 API 参考。
