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

# Mô tả một hình ảnh bằng Midjourney

> Sử dụng CometAPI POST /mj/submit/describe để trích xuất một prompt Midjourney ban đầu từ hình ảnh đã tải lên nhằm remix và lặp lại nhanh hơn.

Sử dụng endpoint này để trích xuất các gợi ý prompt theo phong cách Midjourney từ một hình ảnh đầu vào.

## Route này phù hợp cho việc gì

* Biến một hình ảnh thành các phương án prompt mà bạn có thể remix
* Trích xuất một định hướng hình ảnh trước khi bạn bắt đầu một tác vụ imagine mới
* Xây dựng vòng lặp soạn thảo nhanh hơn khi bạn không muốn tự viết prompt đầu tiên từ đầu

## Quy trình tác vụ

<Steps>
  <Step title="Gửi hình ảnh">
    Tải lên hoặc tham chiếu hình ảnh mà bạn muốn Midjourney mô tả và lưu `task id` được trả về.
  </Step>

  <Step title="Thăm dò tác vụ describe">
    Sử dụng [Fetch Single Task](./task-fetching-api/fetch-single-task) cho đến khi tác vụ hoàn tất và trả về đầu ra giống prompt.
  </Step>

  <Step title="Tái sử dụng prompt đã tạo">
    Lấy phương án prompt phù hợp với ý định của bạn và tiếp tục với [Imagine](./imagine) cho một lượt tạo mới.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/image/midjourney/post-describe.openapi.json POST /mj/submit/describe
openapi: 3.1.0
info:
  title: Describe (image -> text) API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/submit/describe:
    post:
      summary: Describe (image -> text)
      description: >-
        . The extracted prompt suggestions arrive in the task's `promptEn` field
        when you fetch the finished task.
      operationId: describe
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - base64
                - link
              properties:
                botType:
                  type: string
                  description: >-
                    Bot type to use. `MID_JOURNEY` for Midjourney (default),
                    `NIJI_JOURNEY` for Niji.
                  enum:
                    - NIJI_JOURNEY
                    - MID_JOURNEY
                base64:
                  type: string
                  description: >-
                    Base64-encoded image to describe. Use a data URI such as
                    `data:image/png;base64,xxx`. Provide either `base64` or
                    `link`.
                  default: data:image/png;base64,<your-image-base64>
                state:
                  type: string
                  description: >-
                    Custom state string. Returned as-is in the task result and
                    webhook callback for your own tracking.
                link:
                  type: string
                  description: >-
                    URL of the image to describe. Provide either `link` or
                    `base64`.
                  default: https://your-image-host/source.png
              default:
                base64: data:image/png;base64,<your-image-base64>
                link: https://your-image-host/source.png
            examples:
              Default:
                summary: Default
                value:
                  botType: MID_JOURNEY
                  base64: data:image/png;base64,xxx
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - description
                  - properties
                  - result
                properties:
                  code:
                    type: integer
                    description: >-
                      Submission status code. `1` = submitted successfully
                      (`result` carries the task id). `21` = the action opened a
                      confirmation modal; continue with `/mj/submit/modal` using
                      the returned task id. `4` = parameter error; `description`
                      explains the cause.
                  description:
                    type: string
                  properties:
                    type: object
                    properties: {}
                  result:
                    type: integer
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            IMAGE_B64=$(base64 < cat.jpg | tr -d '\n')

            curl https://api.cometapi.com/mj/submit/describe \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d "{
                \"botType\": \"MID_JOURNEY\",
                \"base64\": \"data:image/jpeg;base64,$IMAGE_B64\"
              }"
        - lang: Python
          label: Default
          source: >
            import base64

            import os

            import requests


            with open("cat.jpg", "rb") as f:
                image_b64 = base64.b64encode(f.read()).decode()

            response = requests.post(
                "https://api.cometapi.com/mj/submit/describe",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "botType": "MID_JOURNEY",
                    "base64": "data:image/jpeg;base64," + image_b64,
                },
            )


            task = response.json()

            print(task["code"], task.get("result"))  # poll the task; extracted
            prompts arrive in promptEn
        - lang: JavaScript
          label: Default
          source: >
            import { readFile } from "node:fs/promises";


            const imageB64 = (await readFile("cat.jpg")).toString("base64");


            const response = await
            fetch("https://api.cometapi.com/mj/submit/describe", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    botType: "MID_JOURNEY",
                    base64: `data:image/jpeg;base64,${imageB64}`,
                }),
            });


            const task = await response.json();

            console.log(task.code, task.result); // poll the task; extracted
            prompts arrive in promptEn
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````