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

# Tạo ảnh Flux

> Gọi POST /flux/v1/{model} để tạo ảnh Flux từ prompt và theo dõi trạng thái qua get_result trước khi các liên kết hết hạn.

## Tổng quan

Endpoint `/flux/v1/\{model\}` tạo ra hình ảnh chất lượng cao từ prompt văn bản bằng họ model Flux của Black Forest Labs. Chỉ cần thay model ID trong đường dẫn URL để chuyển đổi giữa các biến thể Flux khác nhau.

<Warning>
  Do có sự khác biệt đáng kể trong danh sách tham số giữa các model thuộc dòng Flux, vui lòng tham khảo [tài liệu chính thức](https://docs.bfl.ai/quick_start/introduction) để biết hướng dẫn sử dụng chi tiết. Danh sách tham số được cung cấp ở đây chỉ mang tính chất tham khảo.

  Sau khi tạo xong, hãy dùng endpoint [`/flux/v1/get_result`](/api/image/flux/flux-query) để truy vấn ảnh đã tạo hoặc theo dõi trạng thái tiến trình.

  Các URL hình ảnh do dịch vụ của BFL trả về sẽ hết hạn sau khoảng **10 phút**. Hãy lưu kết quả đã tạo kịp thời.
</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.

````