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

# Generer et FLUX-bilde

> Send inn FLUX.2 tekst-til-bilde- og referansebildoppgaver via CometAPIs innebygde BFL-kompatible endepunkt.

## Oversikt

`POST /flux/v1/\{model\}` genererer et bilde med en forespørsel i opprinnelig BFL-format. Forespørsler er asynkrone som standard. Lagre toppnivåverdien `id` fra svaret, og foreta deretter polling [`GET /flux/v1/get_result`](/no/api/image/flux/flux-query) med den oppgave-ID-en.

For å vente på bildet i samme forespørsel, send `"async": false` i JSON-brødteksten. Et vellykket synkront svar inneholder `status: "Ready"` og bilde-URL-en i `result.sample`.

API-lekeplassen inneholder eksempler på tekst-til-bilde-forespørsler for FLUX.2 Pro, Flex og Max. Se [Models-siden](/no/overview/models) eller `/v1/models` for modell-ID-er og kontotilgjengelighet.

## Forespørselsfelt

Start med `prompt`, `width`, `height` og `output_format`. Du kan også sende `seed`; det fullførte resultatet kan rapportere seed-verdien som ble brukt, men dette feltet alene gir ikke repeterbart resultat.

Det valgfrie feltet `async` styrer hvordan forespørselen returnerer resultatet. Bruk den boolske JSON-verdien `false` for synkron generering. Bruk `true` eller utelat feltet for asynkron generering. Ikke send en streng som `"false"`.

For redigering med referansebilder sender du en offentlig HTTPS-bilde-URL i `input_image`. Dette feltet støttes av de tre FLUX.2-modellene ovenfor. FLUX.2 Pro godtar også en andre offentlig HTTPS-URL i `input_image_2`; ta med `input_image` hver gang du sender `input_image_2`.

## Generer synkront

Velg **Synkron tekst-til-bilde (FLUX.2 Pro)** i forespørselseksemplene for å sende `"async": false`. Hold tilkoblingen åpen mens bildet genereres. Eksemplet bruker en klienttidsavbruddsgrense på 300 sekunder; dette er en klientinnstilling, ikke en frist for fullføring.

Når svaret har `status: "Ready"`, leser du `result.sample` direkte. Det er ikke nødvendig å polle resultatet. Hvis forespørselen mislykkes, må du håndtere HTTP-feilen før du leser resultatet.

Ikke kombiner `async: false` med `webhook_url` eller `webhook_secret`. Synkrone forespørsler returnerer resultatet direkte og avviser disse webhook-feltene.

## Send inn asynkront og poll

Når `async` er `true` eller utelates, returnerer opprettelsessvaret en oppgave-ID mens genereringen fortsetter. Bruk verdien `id` på toppnivå med CometAPI-resultatendepunktet; klienter bør ikke være avhengige av en `polling_url` som oppgis i svaret.

Poll til resultatendepunktet returnerer `status: "Ready"`. Behandle `Error`, `Failed`, `Failure`, `Task not found`, `Request Moderated` og `Content Moderated` som feil. For andre tilstander fortsetter du å polle innenfor programmets grenser for nye forsøk og tidsavbrudd.

<Warning>
  Når en oppgave er klar, er `result.sample` en midlertidig bilde-URL. Last den ned eller overfør den umiddelbart; ikke stol på en fast levetid.
</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: >-
        Generate an image with a native BFL-format request. Set the JSON boolean
        `async` to `false` to wait for the finished image in this response. A
        successful synchronous response contains `status: "Ready"` and
        `result.sample`. Set `async` to `true` or omit it to submit
        asynchronously, then poll `GET /flux/v1/get_result?id=...` with the
        top-level response `id`.
      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.
                async:
                  type: boolean
                  default: true
                  description: >-
                    Controls whether generation returns asynchronously. Set
                    `false` to wait for the finished image and read
                    `result.sample` from the successful response. Set `true` or
                    omit this field to receive a task ID for polling. Use a JSON
                    boolean, not a string. Do not combine `false` with
                    `webhook_url` or `webhook_secret`.
                input_image:
                  type: string
                  description: >-
                    Public HTTPS URL of the first reference image. Replace the
                    example URL with a publicly accessible image. 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
              Synchronous text to image (FLUX.2 Pro):
                summary: Wait for the finished FLUX.2 Pro image in the create response
                value:
                  prompt: >-
                    A red ceramic teapot on a pale blue table, soft window
                    light.
                  width: 1280
                  height: 768
                  output_format: png
                  seed: 424242
                  async: false
              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: >-
            With `async: false`, successful generation returns `status: "Ready"`
            and the image URL in `result.sample`. With `async: true` or no
            `async` field, 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: >-
                      Task state. A successful synchronous response returns
                      `Ready`. An asynchronous submission can return `Pending`
                      while generation continues.
                  result:
                    type:
                      - object
                      - 'null'
                    description: >-
                      Generation result. A successful synchronous response
                      contains the finished image. An asynchronous submission
                      can return an empty or null result.
                    properties:
                      sample:
                        type: string
                        description: >-
                          Temporary URL of the generated image when the task is
                          Ready. Download or transfer it promptly.
                      seed:
                        type: integer
                        description: >-
                          Seed reported for the completed generation when
                          available.
                  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.
              examples:
                Asynchronous submission:
                  summary: Task submitted for polling
                  value:
                    id: <task_id>
                    status: Pending
                    result: {}
                    polling_url: https://api.cometapi.com/flux/v1/get_result?id=<task_id>
                Synchronous completion:
                  summary: 'Finished image returned by an async: false request'
                  value:
                    id: <task_id>
                    status: Ready
                    result:
                      seed: 424242
                      sample: https://cdn.example.com/generated/flux-image.png
      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: Synchronous text to image (FLUX.2 Pro)
          source: |
            curl \
              https://api.cometapi.com/flux/v1/flux-2-pro \
              --max-time 300 \
              --fail-with-body \
              --silent \
              --show-error \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "A red ceramic teapot on a pale blue table, soft window light.",
                "width": 1280,
                "height": 768,
                "output_format": "png",
                "seed": 424242,
                "async": false
              }'
        - lang: Python
          label: Synchronous 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 red ceramic teapot on a pale blue table, soft window light.",
                    "width": 1280,
                    "height": 768,
                    "output_format": "png",
                    "seed": 424242,
                    "async": False,
                },
                timeout=300,
            )
            response.raise_for_status()
            task = response.json()
            if task.get("status") != "Ready":
                raise RuntimeError("FLUX generation did not return a Ready result")
            print(task["result"]["sample"])
        - lang: JavaScript
          label: Synchronous 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(300_000),
                body: JSON.stringify({
                  prompt: "A red ceramic teapot on a pale blue table, soft window light.",
                  width: 1280,
                  height: 768,
                  output_format: "png",
                  seed: 424242,
                  async: false,
                }),
              },
            );

            if (!response.ok) throw new Error(await response.text());
            const task = await response.json();
            if (task.status !== "Ready") {
              throw new Error("FLUX generation did not return a Ready result");
            }
            console.log(task.result.sample);
        - 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.

````