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

# 生成 Flux 图像

> 调用 POST /flux/v1/{model} 可根据 Prompt 生成 Flux 图像，并在链接过期前通过 get_result 跟踪状态。

## 概述

`/flux/v1/\{model\}` 端点使用 Black Forest Labs 的 Flux 模型家族根据文本 Prompt 生成高质量图像。只需替换 URL 路径中的 model ID，即可在不同的 Flux 变体之间切换。

<Warning>
  由于 Flux 系列模型之间的参数列表存在显著差异，请参阅[官方文档](https://docs.bfl.ai/quick_start/introduction)获取详细使用说明。此处提供的参数列表仅供参考。

  生成后，使用 [`/flux/v1/get_result`](/api/image/flux/flux-query) 端点查询已生成的图像或监控处理状态。

  BFL 服务返回的图像 URL 大约会在 **10 分钟**后过期。请及时保存生成结果。
</Warning>


## OpenAPI

````yaml api/openapi/image/flux/post-flux-generate-image.openapi.json POST /flux/v1/{model}
openapi: 3.1.0
info:
  title: flux generate image API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /flux/v1/{model}:
    post:
      summary: flux generate image
      operationId: flux_generate_image
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            Flux model variant to use, e.g. `flux-pro-1.1`, `flux-pro`,
            `flux-dev`, `flux-pro-1.1-ultra`.
          schema:
            type: string
        - name: Content-Type
          in: header
          required: false
          description: Must be `application/json`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  description: Text prompt describing the image to generate.
                  default: A paper boat floating on calm water at sunrise
                image_prompt:
                  type: string
                  description: >-
                    URL of a reference image to guide the generation style or
                    content.
                width:
                  type: integer
                  description: >-
                    Output image width in pixels. Must be a multiple of 32.
                    Range varies by model.
                height:
                  type: integer
                  description: >-
                    Output image height in pixels. Must be a multiple of 32.
                    Range varies by model.
                steps:
                  type: integer
                  description: >-
                    Number of diffusion steps. Higher values improve quality but
                    increase latency.
                prompt_upsampling:
                  type: boolean
                  description: >-
                    When `true`, automatically enhances the prompt for more
                    detailed results.
                seed:
                  type: integer
                  description: >-
                    Random seed for reproducible outputs. Omit for random
                    generation.
                guidance:
                  type: number
                  description: >-
                    Guidance scale controlling how closely the output follows
                    the prompt. Higher values increase prompt adherence.
                safety_tolerance:
                  type: integer
                  description: >-
                    Safety filter tolerance level. Higher values are more
                    permissive. Range: 0–6.
                interval:
                  type: integer
                  description: >-
                    Diversity interval. Higher values produce more varied
                    outputs at the cost of prompt adherence.
                output_format:
                  type: string
                  description: 'Output image format. Supported values: `jpeg`, `png`.'
                webhook_url:
                  type: string
                  description: URL to receive a POST notification when the task completes.
                webhook_secret:
                  type: string
                  description: >-
                    Secret string included in webhook payloads for request
                    verification.
              default:
                prompt: A paper boat floating on calm water at sunrise
            examples:
              Default:
                summary: Text to image (flux-dev shown; set the model in the URL path)
                value:
                  prompt: A paper boat floating on calm water at sunrise.
                  width: 512
                  height: 512
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: Task id. Pass it to `GET /flux/v1/get_result?id=...`.
                  polling_url:
                    type: string
              example:
                id: <task_id>
                polling_url: https://api.eu2.bfl.ai/v1/get_result?id=<task_id>
                cost: null
                input_mp: null
                output_mp: null
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/flux/v1/flux-dev \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "A paper boat floating on calm water at sunrise.",
                "width": 512,
                "height": 512
              }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/flux/v1/flux-dev",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "prompt": "A paper boat floating on calm water at sunrise.",
                    "width": 512,
                    "height": 512,
                },
            )


            task = response.json()

            print(task["id"])  # poll /flux/v1/get_result?id=... promptly;
            finished results expire
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/flux/v1/flux-dev", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    prompt: "A paper boat floating on calm water at sunrise.",
                    width: 512,
                    height: 512,
                }),
            });


            const task = await response.json();

            console.log(task.id); // poll /flux/v1/get_result?id=... promptly;
            finished results expire
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````