圖像轉圖像 API

圖像轉圖像 API 是一項功能,可讓您將 Meshy 的 AI 圖像編輯能力整合到您自己的應用程式中。使用我們強大的 AI 模型,透過參考圖像和文字提示來轉換與編輯現有圖像。


POST/openapi/v1/image-to-image

建立圖像轉圖像任務

此端點可讓您建立新的圖像轉圖像任務。請參閱圖像轉圖像任務物件,以查看圖像轉圖像任務物件包含哪些屬性。

參數

  • Name
    ai_model
    Type
    string
    必选
    Description

    用於圖像生成的模型 ID。

    可選值:

    • nano-banana:標準模型(每張圖 3 點數)
    • nano-banana-2:能力更強的均衡模型(每張圖 6 點數)
    • nano-banana-pro:Pro 模型,品質更高(每張圖 9 點數)
    • gpt-image-2:OpenAI GPT Image 2,高保真圖像編輯模型(每張圖 12 點數)
  • Name
    prompt
    Type
    string
    必选
    Description

    您想套用至參考圖像的轉換或編輯文字描述。

  • Name
    reference_image_urls
    Type
    array
    必选
    Description

    用於圖像編輯任務的 1 到 5 張參考圖像陣列。目前支援 .jpg.jpeg.png 格式。

    可透過兩種方式提供每張圖片:

    • 可公開存取的 URL:可從公開網路存取的圖片連結。
    • Data URI:圖片的 base64 編碼資料 URI。例如:data:image/jpeg;base64,<your base64-encoded image data>
  • Name
    generate_multi_view
    Type
    boolean
    默认值 false
    Description

    設為 true 時,會生成顯示主體多個角度的多視角圖像。

傳回值

回應的 result 屬性包含新建立圖像轉圖像任務的 id

失敗模式

  • Name
    400 - Bad Request
    Description

    請求不合法。常見原因:

    • 缺少參數:必要參數(如 ai_modelpromptreference_image_urls)未提供。
    • 圖片格式無效:一張或多張參考圖片不是支援的格式。
    • URL 無法存取:一個或多個 reference_image_urls 無法下載。
  • Name
    401 - Unauthorized
    Description

    驗證失敗。請檢查您的 API 金鑰。

  • Name
    402 - Payment Required
    Description

    點數不足,無法執行此任務。

  • Name
    429 - Too Many Requests
    Description

    您已超出請求頻率限制。

Request

POST
/openapi/v1/image-to-image
# 使用文本提示转换参考图像
curl https://api.meshy.ai/openapi/v1/image-to-image \
  -X POST \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "ai_model": "nano-banana",
    "prompt": "Transform this into a cyberpunk style artwork",
    "reference_image_urls": [
      "<your publicly accessible image url or base64-encoded data URI>"
    ]
  }'


 ## 使用 Data URI 示例
curl https://api.meshy.ai/openapi/v1/image-to-image \
  -X POST \
  -H "Authorization: Bearer ${YOUR_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "ai_model": "nano-banana",
    "prompt": "Transform this into a cyberpunk style artwork",
    "reference_image_urls": [
      "data:image/png;base64,${YOUR_BASE64_ENCODED_IMAGE_DATA}"
    ]
  }'

Response

{
  "result": "018a210d-8ba4-705c-b111-1f1776f7f578"
}

GET/openapi/v1/image-to-image/:id

取得影像轉影像任務

此端點允許您透過有效的任務 id 取得影像轉影像任務。請參閱影像轉影像任務物件,查看影像轉影像任務物件包含哪些屬性。

參數

  • Name
    id
    Type
    path
    Description

    要取得的影像轉影像任務的唯一識別碼。

回傳值

回應包含影像轉影像任務物件。請查看影像轉影像任務物件章節以了解詳細資訊。

Request

GET
/openapi/v1/image-to-image/018a210d-8ba4-705c-b111-1f1776f7f578
curl https://api.meshy.ai/openapi/v1/image-to-image/018a210d-8ba4-705c-b111-1f1776f7f578 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

Response

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "type": "image-to-image",
  "ai_model": "nano-banana",
  "prompt": "Transform this into a cyberpunk style artwork",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1692771650657,
  "started_at": 1692771667037,
  "finished_at": 1692771669037,
  "expires_at": 1692771679037,
  "image_urls": [
    "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/image.png?Expires=***"
  ]
}

DELETE/openapi/v1/image-to-image/:id

刪除圖像轉圖像任務

此端點會永久刪除圖像轉圖像任務,包括所有相關聯的圖像和資料。此操作無法復原。

路徑參數

  • Name
    id
    Type
    path
    Description

    要刪除的圖像轉圖像任務 ID。

回傳值

成功時回傳 200 OK

Request

DELETE
/openapi/v1/image-to-image/018a210d-8ba4-705c-b111-1f1776f7f578
curl --request DELETE \
  --url https://api.meshy.ai/openapi/v1/image-to-image/018a210d-8ba4-705c-b111-1f1776f7f578 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

Response

// 成功时返回 200 Ok。

GET/openapi/v1/image-to-image

列出圖像轉圖像任務

此端點可讓您取得圖像轉圖像任務清單。

參數

  • Name
    page_num
    Type
    integer
    Description

    分頁的頁碼。從 1 開始,預設為 1

  • Name
    page_size
    Type
    integer
    Description

    每頁大小限制。預設為 10 筆。最多允許 50 筆。

  • Name
    sort_by
    Type
    string
    Description

    排序欄位。可選值:

    • +created_at:依建立時間遞增排序。
    • -created_at:依建立時間遞減排序。

傳回值

傳回分頁的圖像轉圖像任務物件清單。

Request

GET
/openapi/v1/image-to-image
curl https://api.meshy.ai/openapi/v1/image-to-image?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"

Response

[
  {
    "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
    "type": "image-to-image",
    "ai_model": "nano-banana",
    "prompt": "Transform this into a cyberpunk style artwork",
    "status": "SUCCEEDED",
    "progress": 100,
    "created_at": 1692771650657,
    "started_at": 1692771667037,
    "finished_at": 1692771669037,
    "expires_at": 1692771679037,
    "image_urls": [
      "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/image.png?Expires=***"
    ]
  }
]

GET/openapi/v1/image-to-image/:id/stream

串流式圖像轉圖像任務

此端點使用伺服器傳送事件(SSE)為圖像轉圖像任務串流傳輸即時更新。

參數

  • Name
    id
    Type
    path
    Description

    要進行串流傳輸的圖像轉圖像任務唯一識別碼。

回傳值

以伺服器傳送事件的形式回傳圖像轉圖像任務物件串流。

對於 PENDINGIN_PROGRESS 狀態的任務,回應串流僅包含必要的 progressstatus 欄位。

Request

GET
/openapi/v1/image-to-image/018a210d-8ba4-705c-b111-1f1776f7f578/stream
curl -N https://api.meshy.ai/openapi/v1/image-to-image/018a210d-8ba4-705c-b111-1f1776f7f578/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"

Response Stream

// 错误事件示例
event: error
data: {
  "status_code": 404,
  "message": "Task not found"
}

// 消息事件示例说明任务进度。
// 对于 PENDING 或 IN_PROGRESS 任务,响应流不会包含所有字段。
event: message
data: {
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "progress": 0,
  "status": "PENDING"
}

event: message
data: {
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "type": "image-to-image",
  "ai_model": "nano-banana",
  "prompt": "Transform this into a cyberpunk style artwork",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1692771650657,
  "started_at": 1692771667037,
  "finished_at": 1692771669037,
  "expires_at": 1692771679037,
  "image_urls": [
    "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/image.png?Expires=***"
  ]
}

影像轉影像任務物件

影像轉影像任務物件是 Meshy 用於追蹤從參考影像文字提示輸入生成影像的工作單元。 此物件具有以下屬性:

屬性

  • Name
    id
    Type
    string
    Description

    任務的唯一識別碼。雖然我們使用 k-sortable UUID 作為任務 ID 的實作細節,但您不應對 ID 的格式做任何假設。

  • Name
    type
    Type
    string
    Description

    圖像生成任務的類型。對於圖像轉圖像任務,始終為 image-to-image

  • Name
    ai_model
    Type
    string
    Description

    用於此任務的 AI 模型。可能的值為 nano-banananano-banana-2nano-banana-progpt-image-2

  • Name
    prompt
    Type
    string
    Description

    用於引導圖像轉換的文字 prompt。

  • Name
    status
    Type
    string
    Description

    任務狀態。可能的值為 PENDINGIN_PROGRESSSUCCEEDEDFAILEDCANCELED 之一。

  • Name
    progress
    Type
    integer
    Description

    任務進度。如果任務尚未開始,此屬性為 0。任務成功後,將變為 100

  • Name
    created_at
    Type
    timestamp
    Description

    任務建立時間的時間戳,以毫秒為單位。

  • Name
    started_at
    Type
    timestamp
    Description

    任務開始時間的時間戳,以毫秒為單位。如果任務尚未開始,此屬性為 0

  • Name
    finished_at
    Type
    timestamp
    Description

    任務完成時間的時間戳,以毫秒為單位。如果任務尚未完成,此屬性為 0

  • Name
    expires_at
    Type
    timestamp
    Description

    任務結果過期時間的時間戳,以毫秒為單位。

  • Name
    preceding_tasks
    Type
    integer
    Description

    前面的任務數量。

  • Name
    image_urls
    Type
    array
    Description

    生成圖像的可下載 URL 陣列。啟用 generate_multi_view 時,此陣列包含三個不同視角的圖像 URL;否則,僅包含一個圖像 URL。

  • Name
    task_error
    Type
    object
    Description

    失敗任務的錯誤詳細資訊。完整 task_error 物件參考請查看錯誤處理

  • Name
    consumed_credits
    Type
    integer
    Description

    此任務消耗的積分數。當任務狀態為 PENDINGIN_PROGRESSSUCCEEDED 時返回。對於 FAILED 任務返回 0(失敗時積分會被退還)。

图像转图像任务对象示例

{
  "id": "018a210d-8ba4-705c-b111-1f1776f7f578",
  "type": "image-to-image",
  "ai_model": "nano-banana",
  "prompt": "Transform this into a cyberpunk style artwork",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1692771650657,
  "started_at": 1692771667037,
  "finished_at": 1692771669037,
  "expires_at": 1692771679037,
  "preceding_tasks": 0,
  "image_urls": [
    "https://assets.meshy.ai/***/tasks/018a210d-8ba4-705c-b111-1f1776f7f578/output/image.png?Expires=***"
  ],
  "task_error": {

    "message": ""

  },

  "consumed_credits": 3
}