> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyfast.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# FLUX.1 Kontext [pro]

> 通过 Anyfast API 调用 Black Forest Labs FLUX.1 Kontext [pro] 图片编辑与生成模型。

FLUX.1 Kontext \[pro] 是 Black Forest Labs 推出的上下文感知图片生成模型，通过 Anyfast 提供。可以根据文字生成图片，也可以根据文字指令编辑已有图片。两个接口均为**同步调用** — 直接返回 Base64 编码的图片数据。

* **文生图** — POST JSON 到 `/v1/images/generations`
* **图片编辑** — POST multipart 表单到 `/v1/images/edits`

## 核心能力

* **图片编辑** — 根据文字指令修改已有图片（如"把红色汽车换成蓝色"）
* **文生图** — 根据文字描述生成图片
* **上下文感知** — 理解并保留参考图的上下文信息
* **可复现** — 使用 `seed` 实现确定性生成

## 快速示例

### 文生图

<CodeGroup>
  ```bash cURL theme={null}
  curl https://www.anyfast.ai/v1/images/generations \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "flux-1-kontext-pro",
      "prompt": "A cute baby polar bear",
      "size": "1024x1024"
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://www.anyfast.ai/v1/images/generations",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      json={
          "model": "flux-1-kontext-pro",
          "prompt": "A cute baby polar bear",
          "size": "1024x1024"
      }
  )

  result = response.json()
  # result["data"][0]["b64_json"] 包含 Base64 编码的图片
  ```
</CodeGroup>

### 图片编辑

<CodeGroup>
  ```bash cURL theme={null}
  curl https://www.anyfast.ai/v1/images/edits \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "model=flux-1-kontext-pro" \
    -F "image=@/path/to/photo.jpg" \
    -F "prompt=Change the background to a sunset beach" \
    -F "size=1024x1024"
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://www.anyfast.ai/v1/images/edits",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      files={"image": open("/path/to/photo.jpg", "rb")},
      data={
          "model": "flux-1-kontext-pro",
          "prompt": "Change the background to a sunset beach",
          "size": "1024x1024"
      }
  )

  result = response.json()
  # result["data"][0]["b64_json"] 包含 Base64 编码的图片
  ```
</CodeGroup>

## 文生图参数

| 参数              | 类型      | 必填 | 说明                       |
| --------------- | ------- | -- | ------------------------ |
| `model`         | string  | 是  | 固定为 `flux-1-kontext-pro` |
| `prompt`        | string  | 是  | 图片描述。**⚠️ 提示词必须为英文**     |
| `n`             | integer | 否  | 生成张数。仅支持 `1`             |
| `size`          | string  | 否  | 输出尺寸，如 `1024x1024`       |
| `output_format` | string  | 否  | `jpeg` 或 `png`           |
| `seed`          | integer | 否  | 随机种子，用于复现                |

## 图片编辑参数

| 参数       | 类型      | 必填 | 说明                       |
| -------- | ------- | -- | ------------------------ |
| `model`  | string  | 是  | 固定为 `flux-1-kontext-pro` |
| `image`  | file    | 是  | 需要编辑的图片文件（multipart 上传）  |
| `prompt` | string  | 是  | 编辑指令。**⚠️ 提示词必须为英文**     |
| `n`      | integer | 否  | 生成张数。仅支持 `1`             |
| `size`   | string  | 否  | 输出尺寸，如 `1024x1024`       |

## 响应字段

| 字段                | 说明             |
| ----------------- | -------------- |
| `data[].b64_json` | Base64 编码的图片数据 |
| `created`         | 创建时间戳          |

<Card title="API 参考" icon="code" href="/zh/api-reference/model-api/blackforestlabs/flux-1-kontext-pro">
  查看 FLUX.1 Kontext \[pro] 的交互式 API Playground。
</Card>

<script src="/feedback.js" />
