Image to Image API

Image to Image API は、Meshy の AI 画像編集機能を独自のアプリケーションに統合できる機能です。強力な AI モデルを使用して、参照画像とテキストプロンプトから既存の画像を変換・編集できます。


POST/openapi/v1/image-to-image

Image to Imageタスクを作成

このendpointでは、新しいImage to Imageタスクを作成できます。 Image to Imageタスクオブジェクトに含まれるプロパティを確認するには、 Image to Imageタスクオブジェクトを参照してください。

パラメータ

  • Name
    ai_model
    Type
    string
    必須
    Description

    画像生成に使用するモデルのID。

    利用可能な値:

    • nano-banana: 標準モデル(画像1枚あたり3クレジット)
    • nano-banana-2: 標準よりも高い性能を持つバランス型モデル(画像1枚あたり6クレジット)
    • nano-banana-pro: 品質が強化されたProモデル(画像1枚あたり9クレジット)
    • gpt-image-2: OpenAI GPT Image 2、高忠実度の画像編集モデル(画像1枚あたり12クレジット)
  • Name
    prompt
    Type
    string
    必須
    Description

    参照画像に適用したい変換または編集のテキスト説明。

  • Name
    reference_image_urls
    Type
    array
    必須
    Description

    画像編集タスクに使用する1〜5枚の参照画像の配列。現在、.jpg.jpeg.png形式をサポートしています。

    各画像を指定する方法は2つあります。

    • 公開アクセス可能なURL: 公開インターネットからアクセス可能なURL。
    • Data URI: 画像のbase64エンコードされたData URI。Data URIの例: data:image/jpeg;base64,<your base64-encoded image data>
  • Name
    generate_multi_view
    Type
    boolean
    デフォルト false
    Description

    trueに設定すると、被写体を複数の角度から表示するマルチビュー画像を生成します。

戻り値

レスポンスのresultプロパティには、新しく作成されたImage to Imageタスクのタスクidが含まれます。

失敗モード

  • Name
    400 - Bad Request
    Description

    リクエストは受け入れられませんでした。一般的な原因:

    • パラメータ不足: 必須パラメータ(例: ai_modelpromptreference_image_urls)が不足しています。
    • 無効な画像形式: 1つ以上の参照画像がサポートされていない形式です。
    • 到達不能なURL: 1つ以上のreference_image_urlsをダウンロードできませんでした。
  • Name
    401 - Unauthorized
    Description

    認証に失敗しました。API keyを確認してください。

  • Name
    402 - Payment Required
    Description

    このタスクを実行するためのクレジットが不足しています。

  • Name
    429 - Too Many Requests
    Description

    レート制限を超過しました。

Request

POST
/openapi/v1/image-to-image
# Transform a reference image with a text prompt
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>"
    ]
  }'


 ## Using Data URI example
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

Image to Imageタスクを取得

このendpointでは、有効なタスクidを指定してImage to Imageタスクを取得できます。 Image to Imageタスクオブジェクトに含まれるプロパティについては、 Image to Imageタスクオブジェクトを参照してください。

パラメータ

  • Name
    id
    Type
    path
    Description

    取得するImage to Imageタスクの一意の識別子。

戻り値

レスポンスにはImage to Imageタスクオブジェクトが含まれます。詳細は Image to Imageタスクオブジェクトセクションを確認してください。

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

Image to Imageタスクを削除する

このendpointは、関連するすべての画像とデータを含め、Image to Imageタスクを完全に削除します。この操作は元に戻せません。

パスパラメータ

  • Name
    id
    Type
    path
    Description

    削除するImage to Imageタスクの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

// Returns 200 Ok on success.

GET/openapi/v1/image-to-image

Image to Image タスクの一覧表示

この endpoint では、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: 作成時刻の降順でソートします。

戻り値

Image to Image タスクオブジェクトのページネーションされた一覧を返します。

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

Image to Image タスクをストリーミングする

この endpoint は、Server-Sent Events(SSE)を使用して Image to Image タスクのリアルタイム更新をストリーミングします。

パラメータ

  • Name
    id
    Type
    path
    Description

    ストリーミングする Image to Image タスクの一意の識別子。

戻り値

Server-Sent Events として Image to Image タスクオブジェクト のストリームを返します。

PENDING または IN_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

// Error event example
event: error
data: {
  "status_code": 404,
  "message": "Task not found"
}

// Message event examples illustrate task progress.
// For PENDING or IN_PROGRESS tasks, the response stream will not include all fields.
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

    タスクの一意の識別子です。実装の詳細としてタスク ID には k-sortable UUID を使用していますが、 ID の形式についていかなる仮定も行わないでください

  • Name
    type
    Type
    string
    Description

    画像生成タスクのタイプです。Image to Image タスクの場合、これは常に image-to-image になります。

  • Name
    ai_model
    Type
    string
    Description

    このタスクに使用された AI モデルです。使用可能な値は nano-banananano-banana-2nano-banana-pro、または gpt-image-2 です。

  • Name
    prompt
    Type
    string
    Description

    画像変換の指示に使用されたテキストプロンプトです。

  • 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 が有効な場合、この配列には異なる視点を表す 3 つの画像 URL が含まれます。それ以外の場合は、単一の画像 URL が含まれます。

  • Name
    task_error
    Type
    object
    Description

    失敗したタスクのエラー詳細です。完全な task_error オブジェクトのリファレンスについては、Errors を参照してください。

  • Name
    consumed_credits
    Type
    integer
    Description

    このタスクによって消費されたクレジット数です。タスクステータスが PENDINGIN_PROGRESS、または SUCCEEDED の場合に存在します。FAILED タスクの場合は 0 を返します(失敗時にはクレジットが返却されます)。

Example Image to Image Task Object

{
  "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
}