創意工坊 — 鑰匙扣 API
將你的照片變成可 3D 列印的徽章式鑰匙扣吊飾 —— 一枚帶有浮雕的彩色圓牌。
整個流程分為兩段:prototype 使用來源照片產生一張上色後的概念圖,build 再
將概念圖轉成浮雕 3D 模型。兩段透過 input_task_id 串接。
POST /openapi/creative-lab/keychain/v1/prototypePOST /openapi/creative-lab/keychain/v1/build
建立鑰匙扣 Prototype 任務
從來源照片產生一張上色後的鑰匙扣概念圖。傳回的任務 ID 會作為後續 build 端點的
input_task_id。回應結構詳見
Prototype 任務物件。
參數
- Name
- image_url
- Type
- string
- 必选
- Description
提供給 Meshy 用於鑰匙扣概念圖上色的來源照片。目前支援
.jpg、.jpeg、.png、.webp格式。可透過兩種方式提供圖片:
- 公開網路可存取 URL:可從公開網路存取的 URL。
- Data URI:圖片的 base64 編碼 Data URI,範例:
data:image/jpeg;base64,<your base64-encoded image data>。
- Name
- name
- Type
- string
- Description
選填的任務名稱,僅用於顯示。最長 100 個字元。
傳回值
回應的 result 欄位會傳回新建立的鑰匙扣 prototype 任務的 id。輪詢
查詢任務 或訂閱 串流更新
直到任務狀態變為 SUCCEEDED,再將該 ID 作為
build 端點 的 input_task_id 傳入。
失敗情境
- Name
400 - Bad Request- Description
請求不合法,常見原因:
- 缺少參數:
image_url必填。 - 圖片格式不支援:
image_url不是支援的格式(.jpg、.jpeg、.png、.webp)。 - 圖片尺寸不合法:圖片過小、檔案超過最大大小上限,或像素數超過上限。
- URL 無法存取:
image_url下載失敗(404 或逾時)。 - Data URI 不合法:base64 字串格式錯誤。
- 內容遭審核攔截:圖片被 NSFW 或智慧財產權審核標記。
- 缺少參數:
- Name
401 - Unauthorized- Description
身分驗證失敗,請檢查 API 金鑰。
- Name
402 - Payment Required- Description
點數不足,無法建立任務。
- Name
429 - Too Many Requests- Description
請求超出速率限制。
Request
# Stage 1:生成钥匙扣的上色概念图
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/prototype \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"image_url": "<your publicly accessible image url or base64-encoded data URI>"
}'
Response
{
"result": "018a210d-8ba4-705c-b111-1f1776f7f578"
}


建立鑰匙扣 Build 任務
根據已成功的 prototype 任務,產生最終可 3D 列印的鑰匙扣吊飾。Build 會在 prototype 的上色概念圖之上執行深度圖浮雕管線,並依呼叫方指定的格式產出 一個網格檔案。回應結構詳見 Build 任務物件。
參數
- Name
- input_task_id
- Type
- string
- 必填
- Description
透過同一個 OpenAPI 端點建立的 prototype 任務 ID。該 prototype 必須由同一個 API key 建立、狀態已變為
SUCCEEDED,且產出剛好一張候選圖。透過 webapp 建立的 prototype 任務不接受 —— build 端點只接受由
POST /openapi/creative-lab/keychain/v1/prototype產生的任務,其他來源一律回傳404。
- Name
- name
- Type
- string
- Description
選填的任務名稱,僅用於顯示。最長 100 個字元。
options
選填的浮雕幾何調參欄位。每個欄位都有合理的預設值 —— 只需傳入你想覆寫的欄位即可。
- Name
- badge_shape
- Type
- string
- 預設值 circle
- Description
鑰匙扣吊飾的外形輪廓。可選值:
circle(預設)rounded-recthexagonshieldstar
- Name
- size_mm
- Type
- number
- 預設值 40
- Description
鑰匙扣外接正方形的邊長,單位為毫米。取值範圍:
(0, 400]。
- Name
- relief_height_mm
- Type
- number
- 預設值 2.2
- Description
浮雕相對於底板的最大凸起高度,單位為毫米。取值範圍:
[0, 20]。
- Name
- relief_offset_mm
- Type
- number
- 預設值 0
- Description
浮雕在擠出前的整體垂直偏移量,單位為毫米。取值範圍:
[0, 20]。
- Name
- base_thickness_mm
- Type
- number
- 預設值 0.1
- Description
浮雕背後底板的厚度,單位為毫米。取值範圍:
[0, 20]。
- Name
- has_closed_back
- Type
- boolean
- 預設值 true
- Description
是否將吊飾背面閉合為封閉曲面。設為
false時會輸出開殼模型。
- Name
- relief_curve
- Type
- string
- 預設值 linear
- Description
將深度圖值對應到浮雕高度的傳遞曲線。可選值:
linear(預設)gammas-curve
- Name
- curve_param
- Type
- number
- 預設值 1.0
- Description
傳遞曲線的形狀參數(僅當
relief_curve為gamma時生效)。取值範圍:(0, 10]。
- Name
- invert_depth
- Type
- boolean
- 預設值 false
- Description
反轉深度圖的解讀方向,使較暗的區域對應到較高的浮雕。
- Name
- smoothing
- Type
- number
- 預設值 0.24
- Description
在擷取浮雕之前對深度圖進行平滑處理的強度。取值範圍:
[0, 10]。
- Name
- relief_scale
- Type
- number
- 預設值 1.0
- Description
疊加在
relief_height_mm之上的垂直縮放係數。取值範圍:(0, 10]。
- Name
- depth_threshold
- Type
- number
- 預設值 0.1
- Description
深度圖低通閾值;低於該值的樣本會被截斷為 0。取值範圍:
[0, 1]。
- Name
- remove_background
- Type
- boolean
- 預設值 true
- Description
在製作浮雕之前,自動對 prototype 概念圖進行去背。
- Name
- export_resolution
- Type
- integer
- 預設值 512
- Description
匯出網格時使用的解析度。取值範圍:
[64, 2048]。
output
選填的產物格式選擇,預設為 glb。
- Name
- format
- Type
- string
- 預設值 glb
- Description
Build 回傳的產物包形式。可選值:
glb(預設)—— 回傳單一model.glb,位於model_urls.glb下。obj—— 將model.obj+model.mtl+texture.png打包成 zip,位於model_urls.obj下。zip—— 將產生器產出的所有產物打包成 zip,位於model_urls.bundle_zip下。
回傳值
回應的 result 欄位會回傳新建立的 keychain build 任務的 id。輪詢
查詢任務 或訂閱 串流更新
直到任務狀態變為 SUCCEEDED,即可從 model_urls 中唯一一筆項目下載產物。
失敗情境
- Name
400 - Bad Request- Description
請求不合法,常見原因:
- 缺少參數:
input_task_id為必填。 - UUID 不合法:
input_task_id不是合法的 UUID。 - 父任務未成功:引用的 prototype 任務尚未達到
SUCCEEDED。 - 沒有候選圖:prototype 任務雖然成功,但未產出任何候選圖。
- 參數超出範圍:
options中某個欄位超出了允許的範圍或列舉集合。
- 缺少參數:
- Name
401 - Unauthorized- Description
身分驗證失敗,請檢查 API key。
- Name
402 - Payment Required- Description
點數不足,無法建立任務。
- Name
404 - Not Found- Description
引用的 prototype 任務不存在、屬於其他使用者,或是由 webapp 建立的(只接受 API 模式的 prototype 任務)。
- Name
429 - Too Many Requests- Description
請求超出速率限制。
Request
# Stage 2:基于已成功的 prototype 任务串联 build
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/build \
-X POST \
-H "Authorization: Bearer ${YOUR_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"options": {
"badge_shape": "circle",
"size_mm": 40,
"relief_height_mm": 2.5
},
"output": {
"format": "glb"
}
}'
Response
{
"result": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb"
}

查詢鑰匙扣任務
根據有效的任務 id 查詢 prototype 或 build 任務。URL 路徑必須與任務所屬的階段
一致 —— 透過 /prototype/:id 查詢一個 build 任務會傳回 404,反之亦然。
回應結構詳見 鑰匙扣 Prototype 任務物件 和 鑰匙扣 Build 任務物件。
參數
- Name
- id
- Type
- path
- Description
要查詢的鑰匙扣任務的唯一識別碼。
回傳值
傳回鑰匙扣任務物件,具體結構取決於請求的階段。
Request
# Prototype
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/prototype/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
# Build
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/build/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Prototype Response
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "creative-lab-keychain-prototype",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123456000,
"started_at": 1729123460000,
"finished_at": 1729123486000,
"expires_at": 1729382686000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 6,
"image_urls": [
"https://assets.meshy.ai/***/concept.png?Expires=***"
]
}
Build Response
{
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"type": "creative-lab-keychain-build",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123500000,
"started_at": 1729123510000,
"finished_at": 1729123535000,
"expires_at": 1729382735000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 20,
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.glb?Expires=***"
}
}
刪除鑰匙扣任務
取消一個鑰匙扣任務。如果任務仍處於 PENDING,建立時扣除的點數會自動退還。
已經進入 IN_PROGRESS 的任務可以取消但不退款(worker 可能已經在消耗運算資源)。
已經處於終止狀態(SUCCEEDED、FAILED、CANCELED)的任務無法取消。
URL 路徑必須與任務所屬的階段一致 —— 對 /prototype/:buildId 發送 DELETE 會回傳 404。
路徑參數
- Name
- id
- Type
- path
- Description
要取消的鑰匙扣任務唯一識別碼。
回傳值
成功時回傳 204 No Content,回應本文為空。
失敗情境
- Name
400 - Bad Request- Description
任務已經處於終止狀態,無法取消。
- Name
404 - Not Found- Description
任務不存在、屬於其他使用者,或所屬階段與 URL 路徑不一致。
Request
curl --request DELETE \
--url https://api.meshy.ai/openapi/creative-lab/keychain/v1/prototype/018a210d-8ba4-705c-b111-1f1776f7f578 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response
// 成功时返回 204 No Content,响应体为空。
以串流方式訂閱鑰匙扣任務
透過 Server-Sent Events(SSE)即時訂閱鑰匙扣任務更新。URL 路徑必須與任務所屬的
stage 一致 —— 在 /prototype/:buildId/stream 上開啟 stream 會立即回傳一則
event: error、status_code: 404 的 SSE 事件並關閉連線。
參數
- Name
- id
- Type
- path
- Description
要訂閱的鑰匙扣任務的唯一識別碼。
回傳值
回傳一連串 鑰匙扣 Prototype 或
鑰匙扣 Build 任務物件的 Server-Sent Events。
對於 PENDING 或 IN_PROGRESS 狀態的任務,事件串流只會包含必要的 progress 與
status 欄位。
Request
curl -N https://api.meshy.ai/openapi/creative-lab/keychain/v1/build/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/stream \
-H "Authorization: Bearer ${YOUR_API_KEY}"
Response Stream
// 错误事件示例(stage 不匹配或任务不存在)
event: error
data: {
"status_code": 404,
"message": "Task not found"
}
// 消息事件示例:表示任务进度。
// PENDING / IN_PROGRESS 状态下,事件流不包含全部字段。
event: message
data: {
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"progress": 0,
"status": "PENDING"
}
event: message
data: {
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"type": "creative-lab-keychain-build",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123500000,
"started_at": 1729123510000,
"finished_at": 1729123535000,
"expires_at": 1729382735000,
"task_error": null,
"consumed_credits": 20,
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.glb?Expires=***"
}
}
列出鑰匙扣任務
依階段分頁列出目前 API 金鑰下的鑰匙扣任務。URL 路徑決定階段——
/prototype 會回傳 Prototype 任務;/build 會回傳 Build 任務。
跨階段的任務不會出現在另一邊的回應中。
路徑參數
- Name
- stage
- Type
- path
- 必选
- Description
必須為
prototype或build。集合只會回傳與 URL 階段一致的任務——/prototype永遠不會回傳 Build 任務,反之亦然。
查詢參數
- Name
- page_num
- Type
- integer
- 默认值 1
- Description
分頁頁碼。
- Name
- page_size
- Type
- integer
- 默认值 10
- Description
每頁項目數。最大
50。
- Name
- sort_by
- Type
- string
- 默认值 -created_at
- Description
排序欄位。可選值:
+created_at:依建立時間遞增排序。-created_at:依建立時間遞減排序。
回傳值
回傳依階段篩選的任務物件分頁清單 —— 列出 /prototype 時回傳
鑰匙扣 Prototype 任務物件,
列出 /build 時回傳 鑰匙扣 Build 任務物件。
请求
# 列出 Prototype 任务
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/prototype?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
# 列出 Build 任务
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/build?page_size=10 \
-H "Authorization: Bearer ${YOUR_API_KEY}"
响应(列出 Prototype 任务)
[
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "creative-lab-keychain-prototype",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123456000,
"started_at": 1729123460000,
"finished_at": 1729123486000,
"expires_at": 1729382686000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 6,
"image_urls": [
"https://assets.meshy.ai/***/concept.png?Expires=***"
]
}
]
鑰匙扣 Prototype 任務物件
鑰匙扣 Prototype 任務是 Meshy 用來追蹤「從來源照片生成上色概念圖」這一階段的工作單元。
該階段的輸出會透過 input_task_id 鏈接至
Build 階段。
欄位
- Name
- id
- Type
- string
- Description
任務的唯一識別碼。我們目前使用 k-sortable UUID 作為實作細節,但不應對 id 的格式做任何假設。
- Name
- type
- Type
- string
- Description
任務類型,值為
creative-lab-keychain-prototype。
- Name
- name
- 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 日(星期五)UTC 12:00:00 表示為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
- task_error
- Type
- object
- Description
失敗任務的錯誤詳細資訊。
task_error物件的完整欄位定義詳細資訊請參閱 Errors。
- Name
- consumed_credits
- Type
- integer
- Description
此任務消耗的積分數。狀態為
PENDING、IN_PROGRESS、SUCCEEDED時存在;FAILED時返回0(失敗任務會退款)。
- Name
- image_urls
- Type
- array of strings
- Description
此 prototype 任務產出的概念圖候選 URL 陣列。目前 API 一律只返回一張候選;保留陣列形式,方便未來在不破壞相容性的前提下擴充至多個候選。
钥匙扣 Prototype 任务对象示例
{
"id": "018a210d-8ba4-705c-b111-1f1776f7f578",
"type": "creative-lab-keychain-prototype",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123456000,
"started_at": 1729123460000,
"finished_at": 1729123486000,
"expires_at": 1729382686000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 6,
"image_urls": [
"https://assets.meshy.ai/***/concept.png?Expires=***"
]
}
鑰匙扣 Build 任務物件
鑰匙扣 Build 任務是 Meshy 用來追蹤「從已成功的 prototype 任務產生最終鑰匙扣 3D 網格」這一階段的工作單元。Build 會在 prototype 的概念圖之上執行深度圖浮雕 管線,並依呼叫端指定的格式產出一個網格檔案。
欄位
- Name
- id
- Type
- string
- Description
任務的唯一識別碼。
- Name
- type
- Type
- string
- Description
任務類型,值為
creative-lab-keychain-build。
- Name
- name
- Type
- string
- Description
建立任務時傳入的任務名稱。未傳入時為空字串。
- Name
- status
- Type
- string
- Description
任務狀態。可能值:
PENDING、IN_PROGRESS、SUCCEEDED、FAILED、CANCELED。
- Name
- progress
- Type
- integer
- Description
任務 progress。任務尚未開始時為
0,成功後為100。
- Name
- created_at
- Type
- timestamp
- Description
任務建立時間戳,單位為毫秒。
- Name
- started_at
- Type
- timestamp
- Description
任務開始時間戳,單位為毫秒。
- Name
- finished_at
- Type
- timestamp
- Description
任務完成時間戳,單位為毫秒。
- Name
- expires_at
- Type
- timestamp
- Description
任務結果過期時間戳,單位為毫秒。
- Name
- preceding_tasks
- Type
- integer
- Description
前面尚未處理的任務數。僅當任務狀態為
PENDING時有意義。
- Name
- task_error
- Type
- object
- Description
失敗任務的錯誤詳細資訊。
task_error物件的完整欄位定義詳情請參閱 錯誤。
- Name
- consumed_credits
- Type
- integer
- Description
此任務消耗的積分數。
FAILED時回傳0(失敗任務會退款)。
- Name
- model_urls
- Type
- object
- Description
以產出物名稱作為 key 的下載 URL 字典。一律只包含一筆 —— 即 build 請求中
output.format所指定的格式,key 與請求的格式名稱一致:- Name
glb- Type
- string
- Description
GLB 檔案的下載 URL。當
output.format為glb(預設)時回傳此 key。
- Name
obj- Type
- string
- Description
包含
model.obj、model.mtl與texture.png的 zip 壓縮檔下載 URL。當output.format為obj時回傳此 key。
- Name
bundle_zip- Type
- string
- Description
產生器輸出的所有產出物打包成 zip 後的下載 URL。當
output.format為zip時回傳此 key。
钥匙扣 Build 任务对象示例
{
"id": "019c320e-9a8f-7a1c-9c11-2a1876f8a9bb",
"type": "creative-lab-keychain-build",
"name": "",
"status": "SUCCEEDED",
"progress": 100,
"created_at": 1729123500000,
"started_at": 1729123510000,
"finished_at": 1729123535000,
"expires_at": 1729382735000,
"preceding_tasks": 0,
"task_error": null,
"consumed_credits": 20,
"model_urls": {
"glb": "https://assets.meshy.ai/***/tasks/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/output/model.glb?Expires=***"
}
}