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

# 生成 Bria 图像

> 使用 CometAPI Bria POST /bria/text-to-image 通过文本生成 1MP 照片级真实感图像，并支持增强与灵活的宽高比。

通过纯文本 Prompt 生成可安全用于商业场景的图像。对于在 CometAPI 上的首次请求，请发送 `prompt`，将 `num_results` 保持为 `1`，并从 `aspect_ratio: "1:1"` 开始，除非你已经明确知道所需的最终布局。

## 在以下情况使用此路由

* 你希望通过一次调用获得最终图像
* 你不需要蒙版、图像输入或任务轮询
* 你希望使用一个更易于通过 CometAPI 落地的照片级真实感 Bria 路径

## 从这个请求开始

* 保持 Prompt 简短且具体
* 首次请求使用 `num_results: 1`
* 从 `aspect_ratio: "1:1"` 开始，除非目标布局已经固定
* 如果你需要长期保留，请及时下载返回的 URL

## CometAPI 上的响应行为

Bria 的官方文档描述了更完整的生成流程，并讨论了异步状态流。在 CometAPI 上，此路由使用简化的 JSON 请求，并会立即返回最终的 `result` 数组，而不是返回 `request_id` 加 `status_url`。

<Note>
  CometAPI 代理的是 Bria 的能力，而不是逐字段镜像 Bria 的公共 API。集成时，请以本页 API 参考和 Playground 中展示的请求与响应结构为准。
</Note>


## OpenAPI

````yaml api/openapi/image/bria/post-generate-image.openapi.json POST /bria/text-to-image
openapi: 3.1.0
info:
  title: Generate Image API
  version: 1.0.0
  description: >-
    Generate Bria text-to-image outputs through CometAPI. This route returns
    final image URLs directly.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /bria/text-to-image:
    post:
      summary: Generate Bria images
      description: >-
        Create one or more Bria images from a text prompt. For the most
        predictable first request, keep num_results at 1 and use a square aspect
        ratio.
      operationId: generate_image
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  description: English text prompt for image generation.
                  example: A paper boat floating on calm water at sunrise.
                num_results:
                  type: integer
                  description: >-
                    Number of images to generate. Use 1 for the simplest
                    integration test.
                  default: 1
                aspect_ratio:
                  type: string
                  description: Requested output aspect ratio.
                  enum:
                    - '1:1'
                    - '2:3'
                    - '3:2'
                    - '3:4'
                    - '4:3'
                    - '4:5'
                    - '5:4'
                    - '9:16'
                    - '16:9'
                  default: '1:1'
                seed:
                  type: integer
                  description: Optional seed for reproducible results.
                negative_prompt:
                  type: string
                  description: Optional exclusions for the generated image.
                steps_num:
                  type: integer
                  description: Optional refinement step count.
                  default: 30
                text_guidance_scale:
                  type: integer
                  description: Optional prompt adherence setting.
                  default: 5
                medium:
                  type: string
                  description: Optional visual medium.
                  enum:
                    - photography
                    - art
                prompt_enhancement:
                  type: boolean
                  description: Optional prompt enhancement switch.
                  default: false
                enhance_image:
                  type: boolean
                  description: Optional image detail enhancement switch.
                  default: false
                prompt_content_moderation:
                  type: boolean
                  description: Optional moderation switch.
                  default: false
                ip_signal:
                  type: boolean
                  description: Optional IP warning flag.
                  default: false
                sync:
                  type: boolean
                  description: >-
                    Optional sync hint. CometAPI returns final results
                    immediately without setting this field.
                  default: false
              default:
                prompt: A paper boat floating on calm water at sunrise.
                num_results: 1
                aspect_ratio: '1:1'
            examples:
              Validated request:
                summary: Validated request
                value:
                  prompt: A paper boat floating on calm water at sunrise.
                  num_results: 1
                  aspect_ratio: '1:1'
      responses:
        '200':
          description: Image generation result.
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: array
                    items:
                      type: object
                      required:
                        - urls
                        - seed
                        - uuid
                      properties:
                        urls:
                          type: array
                          items:
                            type: string
                        seed:
                          type: integer
                        uuid:
                          type: string
                example:
                  result:
                    - urls:
                        - https://example.com/generated.png
                      seed: 278741175
                      uuid: 27c39b06-1dfe-11f1-ad57-6ac2c454c04d_278741175
              example:
                result:
                  - urls:
                      - >-
                        https://temp.bria.ai/api/generate_image/A_paper_boat_..._seed_934469972.png
                    seed: 934469972
                    uuid: <uuid>
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/bria/text-to-image \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "prompt": "A paper boat floating on calm water at sunrise.",
                  "num_results": 1,
                  "aspect_ratio": "1:1"
                }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/bria/text-to-image",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                        "prompt": "A paper boat floating on calm water at sunrise.",
                        "num_results": 1,
                        "aspect_ratio": "1:1"
                },
            )


            print(response.json())  # the route responds synchronously with
            result[].urls
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/bria/text-to-image", {
                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.",
                        "num_results": 1,
                        "aspect_ratio": "1:1"
                    }),
            });


            console.log(await response.json()); // the route responds
            synchronously with result[].urls
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````