Creative Lab — 鑰匙扣 API

將一張來源照片轉換為可 3D 列印的鑰匙扣吊飾——一個徽章造型的彩色浮雕深度圖——共分兩個階段:prototype(原型) 階段會根據你輸入的照片產生一張彩色概念圖,隨後 build(構建) 階段會將該概念圖轉換為浮雕 3D 模型。這兩個階段透過 input_task_id 關聯。

  • POST /openapi/creative-lab/keychain/v1/prototype
  • POST /openapi/creative-lab/keychain/v1/build

POST/openapi/creative-lab/keychain/v1/prototype

建立一個 Keychain 原型任務

根據來源照片生成一張彩色化的概念圖。返回的任務 ID 即為建構 endpoint 所需的 input_task_id。回應結構請參見 Keychain 原型任務物件

參數

  • Name
    image_url
    Type
    string
    必選
    Description

    供 Meshy 彩色化為 keychain 就緒概念圖的來源照片。目前支援 .jpg.jpeg.png.webp 格式。

    提供圖像的方式有兩種:

    • 公開可存取的 URL:可從公共網際網路存取的 URL。
    • Data URI:圖像的 base64 編碼 data URI。data URI 範例:data:image/jpeg;base64,<your base64-encoded image data>
  • Name
    name
    Type
    string
    Description

    用於顯示的可選任務名稱。最多 100 個字元。

  • Name
    remove_background
    Type
    boolean
    預設值 false
    Description

    設定為 true 時,原型圖像將以已去除背景的透明 RGBA PNG 形式返回,方便你將主體合成到任意背景上。

    此參數僅控制此 endpoint 返回的圖像,與建構選項中同名的選項(預設值為 true,用於控制在浮雕處理之前去除背景)互相獨立。

回傳值

回應的 result 屬性包含新建立的 keychain 原型任務的任務 id。輪詢 取得任務 endpoint 或訂閱 串流,直到任務達到 SUCCEEDED 狀態,然後將該 ID 作為 input_task_id 傳遞給 建構 endpoint

失敗模式

  • Name
    400 - Bad Request
    Description

    請求不可接受。常見原因:

    • 缺少參數image_url 為必填項。
    • 無效的圖像格式:提供的 image_url 格式不受支援(支援 .jpg.jpeg.png.webp)。
    • 圖像尺寸超出範圍:圖像過小、超過最大檔案大小,或超過最大像素數。
    • URL 無法存取:無法下載 image_url(404 或 timeout)。
    • Data URI 無效:base64 字串格式不正確。
    • 內容被標記:輸入圖像被 NSFW 或智慧財產權 moderation 標記。
  • Name
    401 - Unauthorized
    Description

    身份驗證失敗。請檢查你的 API key。

  • Name
    402 - Payment Required
    Description

    積分不足,無法執行此任務。

  • Name
    429 - Too Many Requests
    Description

    你已超出速率限制。

Request

POST
/openapi/creative-lab/keychain/v1/prototype
# Stage 1: generate a colorized keychain concept image
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"
}
Prototype example
Start with a source photo, then generate the prototype image used by the keychain build stage.
Source photo used as the Creative Lab Keychain input
Prototype input
Creative Lab Keychain prototype output generated from the source photo
Prototype output

POST/openapi/creative-lab/keychain/v1/build

建立一個 Keychain 建構任務

根據成功的原型任務生成最終可用於 3D 列印的鑰匙扣徽章。建構過程會對原型的彩色概念圖執行深度圖浮雕流水線,並依照你指定的格式輸出單一 mesh 製品。回應結構請參見 The Keychain Build Task Object

參數

  • Name
    input_task_id
    Type
    string
    必選
    Description

    透過同一個 OpenAPI endpoint 建立的原型任務的任務 ID。該原型必須使用同一個 API 金鑰建立,必須已達到 SUCCEEDED 狀態,且必須僅生成了一張候選圖片。

    透過 webapp 建立的原型任務不被接受——建構 endpoint 僅接受由 POST /openapi/creative-lab/keychain/v1/prototype 生成的原型任務,其他任何來源都會被拒絕並回傳 404

  • Name
    name
    Type
    string
    Description

    用於展示的可選任務名稱。最多 100 個字元。

options

浮雕 geometry 的可選調整參數。每個欄位都有合理的預設值——你只需要傳送想要覆寫的欄位即可。

  • Name
    badge_shape
    Type
    string
    預設值 circle
    Description

    鑰匙扣徽章的外輪廓形狀。可選值:

    • circle(預設)
    • rounded-rect
    • hexagon
    • shield
    • star
  • 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(預設)
    • gamma
    • s-curve
  • Name
    curve_param
    Type
    number
    預設值 1.0
    Description

    傳遞曲線的形狀參數(僅當 relief_curvegamma 時有意義)。取值範圍:(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, 1]

  • Name
    remove_background
    Type
    boolean
    預設值 true
    Description

    在生成浮雕之前自動移除原型概念圖的背景。

    與同名的原型參數(預設值為 false)是相互獨立的,後者控制的是原型圖像本身是否以帶透明通道的形式回傳。

  • Name
    export_resolution
    Type
    integer
    預設值 512
    Description

    匯出時使用的 mesh 解析度。取值範圍:[64, 2048]

output

可選的輸出格式選擇器。預設值為 glb

  • Name
    format
    Type
    string
    預設值 glb
    Description

    建構回傳的製品包。可選值:

    • glb(預設)——在 model_urls.glb 下回傳單一 model.glb 檔案。
    • obj ——將 model.obj + model.mtl + texture.png 打包為 zip,並在 model_urls.obj 下回傳該包。
    • zip ——將生成器產出的所有製品打包為 zip,並在 model_urls.bundle_zip 下回傳該包。

回傳

回應中的 result 屬性包含新建立的鑰匙扣建構任務的任務 id。請輪詢 Get a Task endpoint,或訂閱 stream,直到任務達到 SUCCEEDED 狀態,然後從 model_urls 中唯一的條目下載製品。

失敗情形

  • Name
    400 - Bad Request
    Description

    請求不可接受。常見原因包括:

    • 缺少參數input_task_id 為必填項。
    • UUID 無效input_task_id 不是有效的 UUID。
    • 父任務未成功:所引用的原型任務尚未達到 SUCCEEDED 狀態。
    • 無候選圖:原型任務已成功,但未生成任何候選圖片。
    • 選項超出範圍options 中的某個欄位超出了允許的範圍或列舉集合。
  • Name
    401 - Unauthorized
    Description

    身份驗證失敗。請檢查你的 API 金鑰。

  • Name
    402 - Payment Required
    Description

    積分不足,無法執行此任務。

  • Name
    404 - Not Found
    Description

    所引用的原型任務不存在、屬於其他使用者,或是透過 webapp 建立的(只有 API 模式下建立的原型任務才能串接到建構任務)。

  • Name
    429 - Too Many Requests
    Description

    你已超出速率限制。

Request

POST
/openapi/creative-lab/keychain/v1/build
# Stage 2: chain build off a succeeded prototype task
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"
}
Build example
The build task converts the selected prototype image into a 3D-printable keychain model.
Creative Lab Keychain build model preview
Build model preview

GET/openapi/creative-lab/keychain/v1/(prototype|build)/:id

檢索 Keychain 任務

根據有效的任務 id 檢索一個 prototype 或 build 任務。URL 路徑 必須與任務所處的階段一致——透過 /prototype/:id 取得 build 任務會回傳 404,反之亦然。

回應結構請參閱 The Keychain Prototype Task ObjectThe Keychain Build Task Object

參數

  • Name
    id
    Type
    path
    Description

    要檢索的 keychain 任務的唯一識別碼。

回傳值

回應包含 keychain 任務物件。其結構取決於所請求的 階段。

Request

GET
/openapi/creative-lab/keychain/v1/prototype/018a210d-8ba4-705c-b111-1f1776f7f578
# 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=***"
  }
}

DELETE/openapi/creative-lab/keychain/v1/(prototype|build)/:id

刪除一個 Keychain 任務

取消一個 keychain 任務。如果任務仍處於 PENDING 狀態,建立時消耗的 積分將被退還。已處於 IN_PROGRESS 狀態的任務將被取消,但不會退款 (worker 可能已經在消耗資源)。已經達到終止狀態 (SUCCEEDEDFAILEDCANCELED)的任務無法被取消。

URL 路徑必須與任務所處的階段相符 —— 對 /prototype/:buildId 執行 DELETE 會回傳 404

路徑參數

  • Name
    id
    Type
    path
    Description

    要取消的 keychain 任務的唯一識別碼。

回傳值

成功時回傳 204 No Content,回應內容為空。

失敗情況

  • Name
    400 - Bad Request
    Description

    該任務已處於終止狀態,無法取消。

  • Name
    404 - Not Found
    Description

    該任務不存在、屬於其他使用者,或其所處階段與 URL 路徑不符。

Request

DELETE
/openapi/creative-lab/keychain/v1/prototype/018a210d-8ba4-705c-b111-1f1776f7f578
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

// Returns 204 No Content on success (empty body).

GET/openapi/creative-lab/keychain/v1/(prototype|build)/:id/stream

流式取得 Keychain 任務

透過 Server-Sent Events(SSE)即時串流取得 keychain 任務的更新。 URL 路徑必須與任務所處的階段相符 —— 若在 /prototype/:buildId/stream 開啟串流,將只會回傳一筆 event: error payload,其中 status_code: 404,隨後連線便會關閉。

參數

  • Name
    id
    Type
    path
    Description

    要進行串流取得的 keychain 任務的唯一識別碼。

回傳

以 Server-Sent Events 的形式回傳一系列 Keychain PrototypeKeychain Build 任務物件。對於處於 PENDINGIN_PROGRESS 狀態的任務,回應串流中只會包含必要的 progressstatus 欄位。

Request

GET
/openapi/creative-lab/keychain/v1/build/019c320e-9a8f-7a1c-9c11-2a1876f8a9bb/stream
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

// Error event example (wrong stage or task not found)
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": "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=***"
  }
}

GET/openapi/creative-lab/keychain/v1/(prototype|build)

取得 Keychain 任務清單

取得單一階段的 keychain 任務分頁清單。URL 路徑決定階段——/prototype 會回傳原型(prototype)任務;/build 會回傳建構(build)任務。其中一個階段的任務不會出現在另一個階段的回應中。

路徑參數

  • Name
    stage
    Type
    path
    必選
    Description

    prototypebuild。此集合只會回傳階段與 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 時為 keychain 原型任務物件, 列出 /build 時為 keychain 建構任務物件

Request

GET
/openapi/creative-lab/keychain/v1/prototype
# List prototype tasks
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/prototype?page_size=10 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

# List build tasks
curl https://api.meshy.ai/openapi/creative-lab/keychain/v1/build?page_size=10 \
  -H "Authorization: Bearer ${YOUR_API_KEY}"

Response (List Prototype Tasks)

[
  {
    "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=***"
    ]
  }
]

Keychain 原型任務物件

Keychain 原型任務物件是 Meshy 用於追蹤從來源照片生成彩色化概念圖的工作單元。此階段的輸出會透過 input_task_id 連結到建構階段

屬性

  • Name
    id
    Type
    string
    Description

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

  • Name
    type
    Type
    string
    Description

    任務的類型。該值為 creative-lab-keychain-prototype

  • Name
    name
    Type
    string
    Description

    建立任務時提供的任務名稱。如果未提供名稱,則為空字串。

  • Name
    status
    Type
    string
    Description

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

  • Name
    progress
    Type
    integer
    Description

    任務的 progress。如果任務尚未開始,此屬性值為 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
    task_error
    Type
    object
    Description

    失敗任務的錯誤詳情。完整的 task_error 物件參考請參閱錯誤

  • Name
    consumed_credits
    Type
    integer
    Description

    此任務消耗的積分數量。當任務狀態為 PENDINGIN_PROGRESSSUCCEEDED 時會顯示此值。對於 FAILED 任務,會回傳 0(失敗時會退還積分)。

  • Name
    image_urls
    Type
    array of strings
    Description

    此原型任務生成的概念圖候選項目的可下載 URL。目前 API 始終只回傳一個候選項目;該欄位設計為陣列,以便未來版本可以在不產生破壞性變更的情況下提供多個候選項目。

Example Keychain Prototype Task Object

{
  "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=***"
  ]
}

Keychain 構建任務物件

Keychain 構建任務物件是 Meshy 用來追蹤從成功完成的原型任務生成最終 3D keychain mesh 的工作單元。構建過程會對原型的概念圖執行深度圖浮雕處理流程,並以呼叫方請求的格式發布單一 mesh 產物。

屬性

  • Name
    id
    Type
    string
    Description

    任務的唯一識別碼。

  • Name
    type
    Type
    string
    Description

    任務的類型。該值為 creative-lab-keychain-build

  • Name
    name
    Type
    string
    Description

    建立任務時提供的任務名稱。如果未提供名稱,則為空字串。

  • Name
    status
    Type
    string
    Description

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

  • 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 物件參考,請參閱 Errors

  • Name
    consumed_credits
    Type
    integer
    Description

    此任務消耗的積分數量。對於 FAILED 任務,返回 0(失敗時積分會被退還)。

  • Name
    model_urls
    Type
    object
    Description

    生成產物的可下載 URL,以產物名稱為鍵。始終只包含一個條目——即透過構建請求的 output.format 所請求的格式。鍵與所請求的格式相符:

    • Name
      glb
      Type
      string
      Description

      GLB 檔案的可下載 URL。當 output.formatglb(預設值)時存在。

    • Name
      obj
      Type
      string
      Description

      指向包含 model.objmodel.mtltexture.png 的 zip 壓縮包的可下載 URL。當 output.formatobj 時存在。

    • Name
      bundle_zip
      Type
      string
      Description

      指向包含產生器輸出的所有產物的 zip 壓縮包的可下載 URL。當 output.formatzip 時存在。

Example Keychain Build Task Object

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