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

# Flux 图像生成 API 文档

> 使用 Flux 图像生成 API 根据文本提示生成高质量图片，适用于文生图、创意出图和自动化视觉内容生成。



## OpenAPI

````yaml openapi/cn/flux.json POST /flux/generate
openapi: 3.1.0
info:
  title: Flux API DOCS
  version: 1.0.0
  description: TTAPI Flux API 接口服务，目前集成了市场上最为领先的视频大模型sora2。
servers:
  - url: https://api.ttapi.io
security: []
paths:
  /flux/generate:
    post:
      description: 根据文本提示使用Flux.1模型生成图像。注意，该接口与Midjourney的区别是单次只能生成一张图片
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateRequest'
      responses:
        '200':
          $ref: '#/components/responses/SuccessResponse'
        '400':
          $ref: '#/components/responses/400Response'
        '401':
          $ref: '#/components/responses/401Response'
      security:
        - CustomApiKey: []
components:
  schemas:
    GenerateRequest:
      type: object
      description: >-
        **注意**：Flux生成图像接口同步返回的并不是任务的最终结果，任务的最终返回结果需要使用`hookUrl`参数接收异步通知，或者通过<a
        href="fetch" target="_self">Flux查询任务结果</a>接口进行查询。
      properties:
        prompt:
          type: string
          description: 生成图像描述词。注意：Flux支持多语言理解能力，但实测英文最佳。
        mode:
          type: string
          example: flux1-dev
          description: 模型版本
          enum:
            - flux1-dev
            - flux1-pro
            - flux-kontext-pro
            - flux-kontext-max
            - flux-2-pro
            - flux-2-flex
            - flux-2-max
            - flux-2-klein-4b
            - flux-2-klein-9b
        size:
          type: string
          example: 1024x1024
          description: 图像尺寸
          enum:
            - 1024x1024
            - 1024x1792
            - 1792x1024
        aspect_ratio:
          type: string
          example: '1:1'
          description: 图像比例
          enum:
            - '21:9'
            - '16:9'
            - '4:3'
            - '3:2'
            - '1:1'
            - '2:3'
            - '3:4'
            - '9:16'
            - '9:21'
        hookUrl:
          type: string
          description: 回调通知地址
      required:
        - prompt
        - mode
  responses:
    SuccessResponse:
      description: 请求成功
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: SUCCESS
              message:
                type: string
                example: success
              data:
                type: object
                example:
                  jobId: jobId
            required:
              - status
              - message
              - data
    400Response:
      description: 参数错误
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: '"prompt" cannot be empty.'
              data:
                type: object
            required:
              - status
              - message
    401Response:
      description: 授权失败
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: Wrong TT-API-KEY or email is not activated.
            required:
              - status
              - message
  securitySchemes:
    CustomApiKey:
      type: apiKey
      in: header
      name: TT-API-KEY
      description: >-
        请前往 <a href='https://dashboard.ttapi.io' target='_blank'>TTAPI 控制台</a>
        获取 API 密钥。

````