> ## 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.

# Generate a FLUX image

> Submit FLUX.2 text-to-image and reference-image tasks through CometAPI's native BFL-compatible endpoint.

## Overview

`POST /flux/v1/\{model\}` submits a native BFL-format image task. Store the top-level response `id`, then poll [`GET /flux/v1/get_result`](/api/image/flux/flux-query) with that task ID.

The API playground includes text-to-image request examples for FLUX.2 Pro, Flex, and Max. Check the [Models page](/overview/models) or `/v1/models` for model IDs and account availability.

## Request fields

Start with `prompt`, `width`, `height`, and `output_format`. You can also send `seed`; the completed result can report the seed used, but that field alone does not establish repeatable output.

For reference-image editing, send a public HTTPS image URL in `input_image`. This field is supported for the three FLUX.2 models above. FLUX.2 Pro also accepts a second public HTTPS URL in `input_image_2`; include `input_image` whenever you send `input_image_2`.

## Submit and poll

The create response can use `status: "processing"` while the task runs. Use its top-level `id` with the CometAPI result endpoint; clients should not depend on a response-supplied `polling_url`.

Poll until the result endpoint returns `status: "Ready"`. Treat `Error`, `Failed`, `Failure`, `Task not found`, `Request Moderated`, and `Content Moderated` as failures. For other states, continue polling within your application's retry and timeout limits.

<Warning>
  When a task is ready, `result.sample` is a temporary image URL. Download or transfer it promptly; do not rely on a fixed lifetime.
</Warning>


## OpenAPI

````yaml api/openapi/image/flux/post-flux-generate-image.openapi.json POST /flux/v1/{model}
openapi: 3.1.0
info:
  title: FLUX image generation API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /flux/v1/{model}:
    post:
      summary: Generate or edit a FLUX image
      description: >-
        Submit a native BFL-format asynchronous task. Store the top-level
        response `id`, then poll `GET /flux/v1/get_result?id=...`. Use that
        CometAPI route instead of depending on a response-supplied
        `polling_url`.
      operationId: flux_generate_image
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            FLUX.2 model ID in the URL path. Check `/v1/models` or the Models
            page for account availability.
          schema:
            type: string
          example: flux-2-pro
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              dependentRequired:
                input_image_2:
                  - input_image
              properties:
                prompt:
                  type: string
                  description: Text prompt describing the image or reference-image edit.
                  example: >-
                    A clean editorial photograph of a red ceramic teapot on a
                    pale blue table, soft window light, no text.
                input_image:
                  type: string
                  description: >-
                    Public HTTPS URL of the first reference image. Replace the
                    example URL with an image that the model provider can
                    retrieve. This editing field is available for the FLUX.2
                    models covered by this reference.
                  example: https://your-image-host/reference-one.jpg
                input_image_2:
                  type: string
                  description: >-
                    Public HTTPS URL of a second reference image for
                    `flux-2-pro`. Replace the example URL and also send
                    `input_image`.
                  example: https://your-image-host/reference-two.jpg
                seed:
                  type: integer
                  description: >-
                    Optional seed value. A completed result can report the used
                    seed; that field alone does not establish repeatable output.
                width:
                  type: integer
                  description: >-
                    Requested output width in pixels. Use a dimension supported
                    by the selected model.
                  example: 1280
                height:
                  type: integer
                  description: >-
                    Requested output height in pixels. Use a dimension supported
                    by the selected model.
                  example: 768
                output_format:
                  type: string
                  description: >-
                    Requested output image format supported by the selected
                    model. The examples use `png`.
                  example: png
            examples:
              Text to image (FLUX.2 Pro):
                summary: Submit a PNG task with FLUX.2 Pro
                value:
                  prompt: >-
                    A clean editorial photograph of a red ceramic teapot on a
                    pale blue table, a small yellow lemon on the right, soft
                    window light, no text.
                  seed: 424242
                  width: 1280
                  height: 768
                  output_format: png
              Text to image (FLUX.2 Flex):
                summary: >-
                  Submit a text-to-image task that requests PNG output with
                  FLUX.2 Flex
                value:
                  prompt: >-
                    A clean editorial photograph of a red ceramic teapot on a
                    pale blue table, a small yellow lemon on the right, soft
                    window light, no text.
                  width: 1280
                  height: 768
                  output_format: png
              Text to image (FLUX.2 Max):
                summary: Submit a PNG task with FLUX.2 Max
                value:
                  prompt: >-
                    A clean editorial photograph of a red ceramic teapot on a
                    pale blue table, a small yellow lemon on the right, soft
                    window light, no text.
                  width: 1280
                  height: 768
                  output_format: png
              Reference image edit (FLUX.2 Flex):
                summary: >-
                  Replace the example URL with a public reference image for
                  FLUX.2 Flex
                value:
                  prompt: >-
                    Turn the subject in the reference image into a hand-painted
                    clay sculpture while preserving the pose, colors, and
                    composition.
                  input_image: https://your-image-host/reference-one.jpg
                  width: 1280
                  height: 768
                  output_format: png
              Two reference images (FLUX.2 Pro):
                summary: >-
                  Replace both example URLs with public reference images for
                  FLUX.2 Pro
                value:
                  prompt: >-
                    Create a magazine-style scene that preserves the subject
                    from reference one and places the object from reference two
                    beside it, no text.
                  input_image: https://your-image-host/reference-one.jpg
                  input_image_2: https://your-image-host/reference-two.jpg
                  width: 1280
                  height: 768
                  output_format: png
      responses:
        '200':
          description: >-
            FLUX task submission response. Save the top-level `id` and poll the
            CometAPI result endpoint.
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - status
                properties:
                  id:
                    type: string
                    description: Task ID to pass to `GET /flux/v1/get_result?id=...`.
                  status:
                    type: string
                    description: >-
                      Submission state. An accepted task can return
                      `processing`.
                  result:
                    type:
                      - object
                      - 'null'
                    description: Task result. It can be empty or null at submission time.
                  polling_url:
                    type:
                      - string
                      - 'null'
                    description: >-
                      Response-supplied convenience URL when returned. Clients
                      should poll the documented CometAPI result route by the
                      top-level `id`.
                  cost:
                    type:
                      - number
                      - 'null'
                    description: >-
                      Numeric billing coefficient when returned. This field is
                      not documented as a currency or credit amount.
                  input_mp:
                    type:
                      - number
                      - 'null'
                    description: Input image megapixels when returned.
                  output_mp:
                    type:
                      - number
                      - 'null'
                    description: Output image megapixels when returned.
                  progress:
                    type:
                      - number
                      - 'null'
                    description: Task progress when returned.
                  details:
                    description: Additional task details when returned.
                  preview:
                    description: Task preview data when returned.
              example:
                id: <task_id>
                status: processing
                result: {}
                polling_url: https://api.cometapi.com/flux/v1/get_result?id=<task_id>
                cost: 3
                output_mp: 0.9375
      x-codeSamples:
        - lang: Shell
          label: Text to image (FLUX.2 Pro)
          source: |
            curl https://api.cometapi.com/flux/v1/flux-2-pro \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                "seed": 424242,
                "width": 1280,
                "height": 768,
                "output_format": "png"
              }'
        - lang: Python
          label: Text to image (FLUX.2 Pro)
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/flux/v1/flux-2-pro",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json={
                        "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                        "seed": 424242,
                        "width": 1280,
                        "height": 768,
                        "output_format": "png"
                    },
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Text to image (FLUX.2 Pro)
          source: |
            const response = await fetch(
              "https://api.cometapi.com/flux/v1/flux-2-pro",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                signal: AbortSignal.timeout(60_000),
                body: JSON.stringify({
                  "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                  "seed": 424242,
                  "width": 1280,
                  "height": 768,
                  "output_format": "png"
                }),
              },
            );

            if (!response.ok) throw new Error(await response.text());
            const task = await response.json();
            console.log(task.id);
        - lang: Shell
          label: Text to image (FLUX.2 Flex)
          source: |
            curl https://api.cometapi.com/flux/v1/flux-2-flex \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                "width": 1280,
                "height": 768,
                "output_format": "png"
              }'
        - lang: Python
          label: Text to image (FLUX.2 Flex)
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/flux/v1/flux-2-flex",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json={
                        "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                        "width": 1280,
                        "height": 768,
                        "output_format": "png"
                    },
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Text to image (FLUX.2 Flex)
          source: |
            const response = await fetch(
              "https://api.cometapi.com/flux/v1/flux-2-flex",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                signal: AbortSignal.timeout(60_000),
                body: JSON.stringify({
                  "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                  "width": 1280,
                  "height": 768,
                  "output_format": "png"
                }),
              },
            );

            if (!response.ok) throw new Error(await response.text());
            const task = await response.json();
            console.log(task.id);
        - lang: Shell
          label: Text to image (FLUX.2 Max)
          source: |
            curl https://api.cometapi.com/flux/v1/flux-2-max \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                "width": 1280,
                "height": 768,
                "output_format": "png"
              }'
        - lang: Python
          label: Text to image (FLUX.2 Max)
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/flux/v1/flux-2-max",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json={
                        "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                        "width": 1280,
                        "height": 768,
                        "output_format": "png"
                    },
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Text to image (FLUX.2 Max)
          source: |
            const response = await fetch(
              "https://api.cometapi.com/flux/v1/flux-2-max",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                signal: AbortSignal.timeout(60_000),
                body: JSON.stringify({
                  "prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
                  "width": 1280,
                  "height": 768,
                  "output_format": "png"
                }),
              },
            );

            if (!response.ok) throw new Error(await response.text());
            const task = await response.json();
            console.log(task.id);
        - lang: Shell
          label: Reference image edit (FLUX.2 Flex)
          source: |
            curl https://api.cometapi.com/flux/v1/flux-2-flex \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "Turn the subject in the reference image into a hand-painted clay sculpture while preserving the pose, colors, and composition.",
                "input_image": "https://your-image-host/reference-one.jpg",
                "width": 1280,
                "height": 768,
                "output_format": "png"
              }'
        - lang: Python
          label: Reference image edit (FLUX.2 Flex)
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/flux/v1/flux-2-flex",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json={
                        "prompt": "Turn the subject in the reference image into a hand-painted clay sculpture while preserving the pose, colors, and composition.",
                        "input_image": "https://your-image-host/reference-one.jpg",
                        "width": 1280,
                        "height": 768,
                        "output_format": "png"
                    },
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Reference image edit (FLUX.2 Flex)
          source: |
            const response = await fetch(
              "https://api.cometapi.com/flux/v1/flux-2-flex",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                signal: AbortSignal.timeout(60_000),
                body: JSON.stringify({
                  "prompt": "Turn the subject in the reference image into a hand-painted clay sculpture while preserving the pose, colors, and composition.",
                  "input_image": "https://your-image-host/reference-one.jpg",
                  "width": 1280,
                  "height": 768,
                  "output_format": "png"
                }),
              },
            );

            if (!response.ok) throw new Error(await response.text());
            const task = await response.json();
            console.log(task.id);
        - lang: Shell
          label: Two reference images (FLUX.2 Pro)
          source: |
            curl https://api.cometapi.com/flux/v1/flux-2-pro \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "Create a magazine-style scene that preserves the subject from reference one and places the object from reference two beside it, no text.",
                "input_image": "https://your-image-host/reference-one.jpg",
                "input_image_2": "https://your-image-host/reference-two.jpg",
                "width": 1280,
                "height": 768,
                "output_format": "png"
              }'
        - lang: Python
          label: Two reference images (FLUX.2 Pro)
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/flux/v1/flux-2-pro",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json={
                        "prompt": "Create a magazine-style scene that preserves the subject from reference one and places the object from reference two beside it, no text.",
                        "input_image": "https://your-image-host/reference-one.jpg",
                        "input_image_2": "https://your-image-host/reference-two.jpg",
                        "width": 1280,
                        "height": 768,
                        "output_format": "png"
                    },
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Two reference images (FLUX.2 Pro)
          source: |
            const response = await fetch(
              "https://api.cometapi.com/flux/v1/flux-2-pro",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                signal: AbortSignal.timeout(60_000),
                body: JSON.stringify({
                  "prompt": "Create a magazine-style scene that preserves the subject from reference one and places the object from reference two beside it, no text.",
                  "input_image": "https://your-image-host/reference-one.jpg",
                  "input_image_2": "https://your-image-host/reference-two.jpg",
                  "width": 1280,
                  "height": 768,
                  "output_format": "png"
                }),
              },
            );

            if (!response.ok) throw new Error(await response.text());
            const task = await response.json();
            console.log(task.id);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````