图像转图像 API
图像转图像 API 是一项功能,允许您将 Meshy 的 AI 图像编辑能力集成到您自己的应用程序中。使用我们强大的 AI 模型,通过参考图像和文本提示来转换和编辑现有图像。
创建图像转图像任务
此端点允许您创建一个新的图像转图像任务。请参阅图像转图像任务对象以查看图像转图像任务对象包含哪些属性。
参数
必需属性
- Name
ai_model- Type
- string
- Description
用于图像生成的模型 ID。
可选值:
nano-banana:标准模型nano-banana-pro:Pro 模型,质量更高
- 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
- Description
设置为
true时,生成显示多个角度主体的多视图图像。未指定时默认为
false。
返回值
响应的 result 属性包含新创建的图像转图像任务的 id。
Request
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"
}
获取图像转图像任务
此端点允许您通过有效的任务 id 获取图像转图像任务。请参阅图像转图像任务对象以查看图像转图像任务对象包含哪些属性。
参数
- Name
id- Type
- path
- Description
要获取的图像转图像任务的唯一标识符。
返回值
响应包含图像转图像任务对象。请查看图像转图像任务对象部分了解详情。
Request
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=***"
]
}
删除图像转图像任务
此端点永久删除图像转图像任务,包括所有关联的图像和数据。此操作不可逆。
路径参数
- Name
id- Type
- path
- Description
要删除的图像转图像任务的 ID。
返回值
成功时返回 200 OK。
Request
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。
列出图像转图像任务
此端点允许您获取图像转图像任务列表。
参数
可选属性
- 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
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=***"
]
}
]
流式图像转图像任务
此端点使用服务器发送事件(SSE)为图像转图像任务流式传输实时更新。
参数
- Name
id- Type
- path
- Description
要流式传输的图像转图像任务的唯一标识符。
返回值
以服务器发送事件的形式返回图像转图像任务对象流。
对于 PENDING 或 IN_PROGRESS 状态的任务,响应流仅包含必要的 progress 和 status 字段。
Request
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-banana或nano-banana-pro。
- Name
prompt- Type
- string
- Description
用于引导图像转换的文本提示。
- Name
status- Type
- string
- Description
任务状态。可能的值为
PENDING、IN_PROGRESS、SUCCEEDED、FAILED、CANCELED之一。
- Name
progress- Type
- integer
- Description
任务进度。如果任务尚未开始,此属性为
0。任务成功后,将变为100。
- Name
created_at- Type
- timestamp
- Description
任务创建时间的时间戳,以毫秒为单位。
时间戳表示自 1970 年 1 月 1 日 UTC 以来经过的毫秒数,遵循 RFC 3339
标准。 例如,2023 年 9 月 1 日星期五下午 12:00:00 GMT 表示为1693569600000。这适用于 Meshy API 中的所有时间戳。
- 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
前面的任务数量。
仅当任务状态为
PENDING时,此字段的值才有意义。
- Name
image_urls- Type
- array
- Description
生成图像的可下载 URL 数组。当启用
generate_multi_view时,此数组包含三个不同视角的图像 URL;否则,仅包含一个图像 URL。
- Name
task_error- Type
- object
- Description
如果任务失败,包含错误消息的错误对象。如果任务成功,
message属性应为空。- Name
message- Type
- string
- Description
详细错误消息。
图像转图像任务对象示例
{
"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": ""
}
}