跳转到内容
最后更新于

youcam-cli

youcam 是 YouCam AI API 的命令列介面。它的每一項 AI 功能(臉部與身體編輯、頭髮、肌膚檢測、彩妝、虛擬試穿、背景與照片編輯、影像與影片生成⋯等)都在終端機中執行,使用與 API 相同的模型與參數。您也可以檢查任務狀態、瀏覽預先定義的範本,以及查詢您的點數與功能費用。

無論您是在評估某項功能、建構整合,或自動化一條流程,CLI 都能派上用場:

  • 評估 YouCam API 的 AI 功能:在您自己的照片上執行某項功能並檢查結果,例如比較風格,或確認某項功能是否符合您的產品需求。無需寫程式。
  • 整合 API:在撰寫程式碼之前,先從終端機嘗試任何端點。選項與請求欄位一對一對對應,每項功能都連結到它的API 參考文件。
  • AI agents:Claude Code、Cursor、Codex 及其他 agent,可以將任何 YouCam 功能當作一般的 shell 指令使用。每個指令都會輸出 JSON,失敗時以代碼 1 結束,每個功能與選項都在 --help 中自我說明,且在送出請求前就會拒絕無效的值。
  • 自動化與批次作業:透過 shell 腳本、CI 管線或容器,對整批產品照與人像執行功能。本地檔案會由您代為上傳,無需自行撰寫上傳步驟。

需求

安裝

npm install -g @youcam_cli/youcam-cli

# 驗證安裝結果
youcam --help

# YouCam CLI 的版本
youcam --version

若要解除安裝,請執行 npm uninstall -g @youcam_cli/youcam-cli。

認證

youcam auth login <apiKey> 會一次儲存您的 API 金鑰,金鑰儲存在本地,之後每個指令都會重複使用它。

youcam auth login <apiKey>

# 或以旗標明確指定
youcam auth login --api-key <apiKey>

# 移除已儲存的 API 金鑰(登出 CLI 工具)
youcam auth logout

# 列出可用的認證選項
youcam auth --help

auth login 會將金鑰寫入一個純 JSON 檔案,~/.youcam-cli/credentials.json:

{
  "apiKey": "<your-api-key>"
}
  • 每個 run、status、template 與 client 指令都會自動讀取這個檔案。
  • 當設定了 YOUCAM_CLI_API_KEY 環境變數時,它會優先於已儲存的金鑰。

快速開始

執行您的第一個 AI 任務,從檢查點數到下載結果。這會執行一個真實任務,因此會使用點數(見查詢功能費用)。

每個 YouCam 功能都以背景任務執行:您啟動它,取得一個 task_id,然後檢查那個 task_id 直到結果就緒。

1. 安裝並登入(詳細說明見安裝與認證)

npm install -g @youcam_cli/youcam-cli
youcam auth login <apiKey>

2. 檢查您的點數

youcam client credit

回應:

{
  "status": 200,
  "results": [
 {
  "id": 0,
  "type": "ApiPaygToken",
  "amount": 8193,
  "amount_dec": 8193,
  "expiry": 1801958399000
 }
  ]
}

amount 是每個項目中的點數數量,expiry 是到期時間(自 Unix epoch 起算的毫秒數)。這個指令名為 credit,是因為 API 將一個單位稱為「credit」(見點數與功能費用)。

3. 啟動任務

這會使用 AI Photo Enhance 將一張範例照片修復為兩倍解析度:

youcam run enhance --src_file "https://plugins-media.makeupar.com/strapi/assets/hair_color_03_81c0c8a3c8.jpg" --scale 2

回應:

{
  "status": 200,
  "data": {
 "task_id": "32tu4jQvRbI9NfnKlw13cls8tyT1zA2ZoOtKq-RkiTL_FrIEOLYHJX1HxYVrnWz"
  }
}

CLI 也會印出下一步的指令。它會輸出到 stderr,因此 stdout 對腳本而言保持純粹的 JSON:

執行 `youcam status enhance 32tu4jQvRbI9NfnKlw13cls8tyT1zA2ZoOtKq-RkiTL_FrIEOLYHJX1HxYVrnWz` 以檢查結果。

若要使用您自己的照片,請改傳本地路徑,例如 --src_file ./photo.jpg。

4. 檢查並下載結果

youcam status enhance <task_id>

任務仍在處理時,task_status 為 running;數秒後再次執行指令。完成後:

{
  "status": 200,
  "data": {
 "error": null,
 "results": {
  "url": "https://yce-us.s3-accelerate.amazonaws.com/ttl30/.../509f8acd-8d41-4459-aa31-1d4738d7a922.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&...&X-Amz-Expires=7200&..."
 },
 "task_status": "success"
  }
}

results.url 就是增強後的圖片。它是一個簽章連結,2 小時後失效(X-Amz-Expires=7200),請盡快下載。

後續步驟

  • 瀏覽可用的 AI 功能,並執行 youcam run <feature> --help 查看該功能的選項。
  • 在執行 AI 任務中了解選項、檔案與 JSON 參數的運作方式。
  • 有些功能會先偵測臉部或身體,見前處理。

點數與功能費用

點數是您使用 YouCam API 時消耗的額度,每個 AI 功能使用的數量不同。API(以及 CLI)將一個單位稱為「credit」,這就是指令名為 client credit 與 client credit-history 的原因。請見官方 FAQ 中的「Unit(點數)是什麼?如何使用?」。

檢查您的點數

youcam client credit  # 剩餘點數
youcam client credit-history  # 點數使用歷史

查詢功能費用

在大量執行之前,先查詢某項功能會消耗多少點數。

youcam client feature-cost

兩個指令都以 --page_size 與 --starting_token <token> 進行結果分頁:

  • credit-history:--page_size <1-30>,預設 20。
  • feature-cost:--page_size <1-20>,預設 20。

註:前處理偵測任務與列出預先定義的範本不會消耗點數。

指令總覽

youcam <command> [options]

Commands:
  auth Manage authentication credentials
  run  Run an AI task
  status  Check the status of an AI task
  template   List predefined templates
  client  Get account/credit info
  help Display help for a command

每個指令與子指令都支援 -h, --help,顯示它自己的用法與選項:

youcam run --help
youcam run face-swap --help

結果以 JSON 輸出。指令在請求失敗時以代碼 1 結束。

API ↔ CLI 指令對應

API 參考文件中的每個端點,都能以可預期的方式對應到一個 CLI 指令:

REST 端點CLI 指令
POST /s2s/v{ver}/task/{feature}youcam run <feature> [options]
GET /s2s/v{ver}/task/{feature}/{task_id}youcam status <feature> <task_id>
POST /s2s/v{ver}/task/{feature}/pre-processyoucam run pre-process <feature> [options]
GET /s2s/v{ver}/task/{feature}/pre-process/{task_id}youcam status pre-process <feature> <task_id>
GET /s2s/v{ver}/task/template/{feature}youcam template <feature> [--page_size] [--starting_token]
公開的 makeup-vto 圖樣目錄youcam template makeup-vto <categories...>
GET /s2s/v1.0/client/credityoucam client credit
GET /s2s/v1.0/client/credit/historyyoucam client credit-history [--page_size] [--starting_token]
GET /s2s/v2.0/credit/feature-costyoucam client feature-cost [--page_size] [--starting_token]
POST /s2s/v2.0/file + 預簽章 PUT 上傳當檔案選項是本地路徑時自動完成(見上傳檔案)

從 API 參考文件推導 <feature> 的經驗法則:

  • CLI 的功能名稱,是 {task_id} 之前的那個路徑段,例如 /s2s/v2.0/task/abs-shape/{task_id} → abs-shape。

  • API 版本前綴(v2.0、v2.1⋯)由您代為處理:每個指令都會呼叫 API 參考文件中最新的 API 版本,例如 skin-analysis 與 hair-transfer 呼叫 /s2s/v2.1/...。當某功能有多個引擎版本時,只提供最新版本,例如提供 cloth-v4 而不提供 cloth-v3。

  • 少數端點有一個額外的路徑段,去掉它即可得到 CLI 名稱:

    API 路徑CLI 指令
    /s2s/v2.0/task/2d-vto/earring(necklace、ring、bracelet、watch 相同)youcam run earring
    /s2s/v2.0/task/image-to-image/youcam、/text-to-image/youcam、/image-to-video/youcam、/text-to-video/youcamyoucam run image-to-image、run text-to-image、run image-to-video、run text-to-video
    /s2s/v2.0/task/colorize/color-correctyoucam run color-correct
  • 請求內容的屬性,會變成對應 run 指令上的 --<property_name> 選項(見上傳檔案與傳遞 JSON 參數)。page_size、starting_token 等查詢參數也會變成 --<param_name> 選項。

以 AI Hair Color Virtual Try-On 為例,它的兩個端點是:

POST /s2s/v2.0/task/hair-color   { src_file_url | src_file_id, preset?, pattern?, palettes? }
GET  /s2s/v2.0/task/hair-color/{task_id}

對應到這些 CLI 指令:

youcam run hair-color --src_file <url-or-path> [--preset <value> | --pattern <json> --palettes <json>]
youcam status hair-color <task_id>

要套用預設顏色:

youcam run hair-color --src_file "https://plugins-media.makeupar.com/strapi/assets/hair_color_09_76a7a1081e.jpg" --preset "Honey Blonde"
youcam status hair-color <task_id>

run 指令會送出這個請求內容:

{
  "src_file_url": "https://plugins-media.makeupar.com/strapi/assets/hair_color_09_76a7a1081e.jpg",
  "preset": "Honey Blonde"
}

若要改套用自訂顏色,請傳入 pattern 與 palettes 物件:

youcam run hair-color --src_file "https://plugins-media.makeupar.com/strapi/assets/hair_color_09_76a7a1081e.jpg" \
  --pattern '{"name": "full"}' \
  --palettes '[{"color": "#8B4513", "color_intensity": 80, "shine_intensity": 50}]'
youcam status hair-color <task_id>

等價的 JSON 請求內容為:

{
  "src_file_url": "https://plugins-media.makeupar.com/strapi/assets/hair_color_09_76a7a1081e.jpg",
  "pattern": { "name": "full" },
  "palettes": [{ "color": "#8B4513", "color_intensity": 80, "shine_intensity": 50 }]
}

youcam run 會印出新的 task_id;將它傳給 youcam status 並重複執行,直到 task_status 為 success。

執行 AI 任務

每個 AI 功能都是 run 的一個子指令。選項依功能而異;請對該功能使用 --help 查看它的輸入。

youcam run <feature> [options]

例如,執行 AI Abs Filter:

youcam run abs-shape --src_file "https://example.com/photo.jpg" --mode "Six-pack" --intensity 2

執行任務會回傳一個 task_id,您用它來檢查狀態。

  • 前處理: 少數功能會先偵測照片中的臉部或身體,讓您可以選擇要處理哪一個人。見前處理。
  • 範本: 某些功能接受現成的風格預設,透過 --template_id 指定。見列出預先定義的範本。
  • 驗證: 選項值會在送出之前,依 API schema 檢查。有固定值集合的選項會在 --help 中列出,無效的值會被拒絕並列出允許的選項。

上傳檔案

每個接受圖片或影片的功能,都將其暴露為單一的 --src_file 選項,儘管 API 接受兩個互斥的欄位:src_file_url(公開網址)或 src_file_id(已上傳檔案的 ID)。CLI 會依您傳入的內容選擇正確的那一個:

  • 公開可存取的網址會以 src_file_url 送出。不會上傳任何東西。
    youcam run enhance --src_file "https://example.com/photo.jpg" --scale 2
  • 本地檔案路徑會由您代為上傳,任務以 src_file_id 送出:
    1. POST /s2s/v2.0/file 註冊檔案(名稱、內容類型、大小),並回傳一個預簽章的上傳網址與一個 file_id。
    2. 檔案的位元組以 PUT 傳送至該預簽章網址。
    3. run <feature> 被呼叫時,src_file_id 設為那個 file_id。
    youcam run enhance --src_file ./photo.jpg --scale 2
    在 PowerShell 或 cmd 中,Windows 路徑也可以使用:
    youcam run enhance --src_file .\photo.jpg --scale 2

注意事項:

  • 本地檔案必須是 .jpg、.jpeg、.png 或 .mp4。
  • 大小、解析度與長度限制依功能而異,過大的檔案會使任務失敗,在 status 中出現 exceed_max_filesize。
  • 沒有獨立的上傳 CLI 指令,上傳只透過檔案選項發生。

其他檔案選項

除了 --src_file,某些功能需要額外的圖片(遮罩、參考照片、產品照)。它們遵循相同的規則:傳入公開網址或本地路徑,本地路徑會由您代為上傳。

選項內容值使用於
--src_file <input>主要來源照片或影片單一多數功能
--src_files <inputs...>多張來源照片多個hair-frizziness-detection、hair-type-detection、image-to-image
--ref_file <input>要複製的參考圖片(例如彩妝造型、一套服飾、一項產品)單一bag、cloth-v4、eye-color-vto、hair-transfer、hat、mu-transfer、ai-nail、scarf、shoes-transfer、bg-replace-vid、face-swap-vid
--ref_files <inputs...>多張參考圖片(例如每個目標一張臉、產品照)多個bracelet、earring、face-swap、nail-vto、necklace、ring、watch
--msk_file <input>覆蓋來源的遮罩:白色標示要變更的區域,黑色維持原樣單一generative-fill、obj-replace、obj-rem-vid
--srcmsk_file <input>在來源中隔離相關身體部位的遮罩(例如耳朵、頸部、手腕)單一bracelet、earring、necklace、ring、watch
--refmsk_files <inputs...>對應每個 --ref_files 項目的遮罩,順序相同多個bracelet、earring、ring、watch

帶有 ... 的選項,在同一個旗標後接受多個值,以空格分隔(不是逗號):

youcam run face-swap \
  --src_file group-photo.jpg \
  --ref_files person-a.jpg person-b.jpg \
  --face_mapping '[{"index":0,"position":0},{"index":1,"position":1}]'

若某個多值選項混合了公開網址與本地路徑,例如 --ref_files https://example.com/a.jpg ./b.jpg,其中的每個檔案都會被上傳,網址也包括在內:CLI 會下載每個網址、像本地檔案一樣上傳它,並將全部以檔案 ID 送出(例如 ref_file_ids)。這些網址必須提供 JPG、PNG 或 MP4。若要讓網址以網址形式送出,在該選項中只傳網址。

執行 youcam run <feature> --help 可查看該功能確實接受哪些選項。

選項語法

下列形式是等價的,請使用您偏好的寫法:

youcam run skin-simulation --src_file https://example.com/face.png --acne 1
youcam run skin-simulation --src_file=https://example.com/face.png --acne=1
youcam run skin-simulation --src_file="https://example.com/face.png" --acne="1"
  • 只有在值包含空格,或包含您的 shell 會特殊處理的字元(例如網址中的 &,或 JSON)時,才需要引號。
  • 接受多個值的選項,可以在同一個旗標後以空格分隔,或以重複的旗標:
    • --src_files a.jpg b.jpg
    • --src_files=a.jpg --src_files=b.jpg
    • 不是 --src_files=a.jpg b.jpg,這種寫法會被拒絕。

傳遞 JSON 參數

在 --help 中顯示為 <json>(而非 <value>)的選項,對應 API 請求內容中的 object 或 array 欄位。請將整個結構作為單一 JSON 值傳入:

  • 內嵌 JSON,例如 --pattern '{"name":"full"}'
  • 指向 .json 檔案的路徑,例如 --effects ./effects.json
  • 用 - 從 stdin 讀取 JSON,例如 cat effects.json | youcam run makeup-vto --src_file photo.jpg --effects -

內嵌 JSON 的引號:

# bash / zsh / macOS / Linux / Git Bash:單引號可保護雙引號
youcam run hair-color --src_file photo.jpg --pattern '{"name":"full"}' --palettes '[{"color":"#8B4513","color_intensity":80,"shine_intensity":50}]'

# Windows PowerShell:跳脫內部的雙引號
youcam run hair-color --src_file photo.jpg --pattern '{\"name\":\"full\"}' --palettes '[{\"color\":\"#8B4513\",\"color_intensity\":80,\"shine_intensity\":50}]'

巢狀物件與陣列: hair-color 的 --pattern 是 object,--palettes 是 {color, color_intensity, shine_intensity} 物件的 array(全染模式一個,漸層模式兩個):

youcam run hair-color \
  --src_file photo.jpg \
  --pattern '{"name":"full"}' \
  --palettes '[{"color":"#FF5733","color_intensity":80,"shine_intensity":50}]'

photo.jpg 上傳並解析成 src_file_id 後,CLI 會將這個內容送至 POST /s2s/v2.0/task/hair-color:

{
  "src_file_id": "<file_id from the upload>",
  "pattern": {
 "name": "full"
  },
  "palettes": [
 {
  "color": "#FF5733",
  "color_intensity": 80,
  "shine_intensity": 50
 }
  ]
}

每個 --<option> <json> 的值,都原樣作為該屬性的值:--pattern 成為 pattern 物件,--palettes 成為 palettes 陣列。不會重新命名或重塑結構,也不會為未提供的選項加入預設值。

深度巢狀陣列: makeup-vto 的 --effects 是特效物件的陣列,其中一些有自己的 pattern 與 palettes。多行 JSON 也可以使用:

youcam run makeup-vto --src_file photo.jpg --effects '[
  {"category":"skin_smooth","skinSmoothStrength":55,"skinSmoothColorIntensity":45},
  {"category":"blush","pattern":{"name":"1color1"},"palettes":[
 {"color":"#e19f9f","texture":"matte","colorIntensity":60}
  ]}
]'

1color1 等圖樣名稱來自 youcam template makeup-vto(見列出 makeup-vto 圖樣名稱)。

無效的 JSON,或類型錯誤的值,會在送出請求前被拒絕,並指出問題欄位,例如 Invalid value for --palettes: [{"color":123}] (0.color: Invalid input: expected string, received number)。

檢查任務狀態

youcam status <feature> <task_id>
# 或
youcam status <feature> --task_id <task_id>

範例:

youcam status abs-shape 1234567890abcdef

輪詢直到 task_status 為 success(或 error);回應接著會包含結果,例如輸出檔案網址。若是前處理任務,請使用 youcam status pre-process <feature> <task_id>。

前處理(臉部與身體偵測)

前處理任務不使用點數,只有主要任務會使用。

對下列功能而言,一張照片可能包含多人,因此您要選擇處理哪一位。youcam run pre-process <feature> 會偵測照片中的臉部或身體,並以清單回傳。清單中每個對象依其在清單中的位置編號:第一位是 0,第二位是 1,依此類推。

  1. 偵測:youcam run pre-process <feature> --src_file <photo> 回傳一個 task_id。
  2. 讀取偵測結果:youcam status pre-process <feature> <task_id> 會列出偵測到的臉部或身體。清單的形式依功能而異:body-reshape 回傳 results.result[],為相對於圖片尺寸的框(0–1),而 face-swap 回傳 results.faces[].bbox,為像素框 [x1, y1, x2, y2](左上角與右下角)。
  3. 在同一張照片上執行該功能,使用下表中的選項傳入您選擇的編號:
功能接受偵測到的臉部或身體編號的選項
body-reshape--index <number>
face-lift--index <number>
face-reshape--index <number>
fitzpatrick-scale-analyzer--index <number>
teeth-whiten--index <number>
face-swap每個 --face_mapping 項目中的 "position"。該項目的 "index" 決定要使用哪個 --ref_files 圖片

例如,youcam run face-lift --src_file <photo> --index 1 ... 會拉提第二個偵測到的臉。完整執行與真實輸出請見範例工作流程。

列出預先定義的範本

有些功能附帶可直接使用的範本(風格或造型預設),您以 --template_id 引用,不必自行建構參數。

youcam template <feature> [--page_size <1-20>] [--starting_token <token>]

<feature> 為下列其中之一:

類別功能
頭髮與鬍鬚hair-bang、hair-curl、hair-ext、hair-transfer、hair-vol、beard-style
彩妝與試妝look-vto、fabric
影像ai-avatar、ai-studio、headshot、bg-replace
影片video-trans

關於 makeup-vto 的圖樣細節,請見列出 makeup-vto 圖樣名稱。

範例:

youcam template ai-avatar --page_size 10
youcam run ai-avatar --src_file ./photo.jpg --template_id <id> --output_count 1

將回應中的 next_token 作為 --starting_token 傳入,即可取得下一頁。

當 ai-avatar 任務成功時,youcam status ai-avatar <task_id> 會在 results.output[].url 中列出生成的圖片,每個輸出有一個項目。

列出 makeup-vto 圖樣名稱

makeup-vto 特效以名稱挑選形狀,例如腮紅的 "pattern":{"name":"1color1"},或唇色的 "shape":{"name":"plump"}。列出每個特效類別的有效名稱:

youcam template makeup-vto <categories...>

傳入 blush、bronzer、contour、eyebrows、eyeliner、eyeshadow、eyelashes、lipshape、lipliner、highlighter 中的一個或多個(或在 --category 後使用相同名稱)。至少需要一個。這些目錄是公開的,因此列出它們不會使用點數。

youcam template makeup-vto blush lipshape

結果以類別為索引。使用項目的 label 作為圖樣名稱;colorNum(僅腮紅、眼線與眼影)表示該圖樣需要幾個 palettes:

{
  "blush": [
 {
  "category": "1 color",
  "label": "1color1",
  "thumbnail": "https://app-cdn-01.makeupar.com/.../a53cd4f4-43b6-4e19-b85a-ec7a95c6a47f.jpg",
  "tags": [
   { "id": 100, "name": "Blush 3D" },
   { "id": 103, "name": "Oblong" }
  ],
  "colorNum": 1
 }
  ],
  "lipshape": [
 {
  "category": "general",
  "label": "original",
  "thumbnail": "https://plugins-media.makeupar.com/wcm-saas/images/lipshapes/original.png",
  "tags": []
 }
  ]
}

無法取得的類別會顯示 { "error": "..." },且指令以代碼 1 結束。

可用的 AI 功能

將下列任一项作為 <feature> 傳給 run 與 status。每一項都連結到它的 API 參考頁面。有偵測步驟的功能請見前處理。可與 youcam template 搭配的功能請見列出預先定義的範本。

彩妝

肌膚、臉部與身體

頭髮與鬍鬚

虛擬試穿/試戴

影像

影片

執行 youcam run <feature> --help 可查看每個功能接受的確切參數。

範例工作流程

這裡完整示範 AI Body Reshape:從偵測照片中的身體、選擇一位、進行塑形,到取得結果。以下的請求與回應內容,取自使用這張範例照片的真實執行:

1. 啟動偵測(前處理)任務

youcam run pre-process body-reshape \
  --src_file "https://plugins-media.makeupar.com/strapi/assets/body_reshape_01_d10c50c97d.jpg"

回應:

{
  "status": 200,
  "data": {
 "task_id": "CKPWaMO-olxd1ECr_3tTDXW5Gu_tQw0EKgN0-dU27zSyXhV8cJR2TzYLMhDqD"
  }
}

2. 取得偵測到的身體

youcam status pre-process body-reshape CKPWaMO-olxd1ECr_3tTDXW5Gu_tQw0EKgN0-dU27zSyXhV8cJR2TzYLMhDqD

回應:

{
  "status": 200,
  "data": {
 "error": null,
 "results": {
  "result": [
   {
   "left": 0.35347824096679686,
   "top": 0.022326231002807617,
   "width": 0.3041056156158447,
   "height": 0.951037073135376
   }
  ],
  "timed": 4565
 },
 "task_status": "success"
  }
}

results.result 中的每個項目是一位偵測到的人,以相對於圖片尺寸的邊界框表示(0–1)。它在陣列中的位置,就是接下來要傳的 --index;這張照片只有一人,因此 index 為 0。

3. 對選定的人執行主要任務

youcam run body-reshape \
  --src_file "https://plugins-media.makeupar.com/strapi/assets/body_reshape_01_d10c50c97d.jpg" \
  --version 1.0 \
  --index 0 \
  --features '{"slim": 20}'

回應:

{
  "status": 200,
  "data": {
 "task_id": "ZV3WIzcB1rk7I5o8hMxKP5VdgIEpnHf7VOpsk1YC76tZy2Wur0lg4Bunb3KY-7Qa"
  }
}

4. 輪詢主要任務直到完成

youcam status body-reshape ZV3WIzcB1rk7I5o8hMxKP5VdgIEpnHf7VOpsk1YC76tZy2Wur0lg4Bunb3KY-7Qa

任務執行期間,task_status 為 running;每隔數秒重複執行指令。成功後(GET /s2s/v2.0/task/body-reshape/{task_id}):

{
  "status": 200,
  "data": {
 "error": null,
 "results": {
  "url": "https://yce-us.s3-accelerate.amazonaws.com/ttl30/.../0b333891-60be-4cd1-81cd-7d8cae35b3eb.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&...&X-Amz-Expires=7200&...",
  "timed": 12131,
  "slim": true
 },
 "task_status": "success"
  }
}

results.url 就是塑形後的圖片。它是一個會失效的簽章連結(X-Amz-Expires=7200,即 2 小時),請在任務成功後盡快下載。

偵錯指南

CLI 發送的是標準的 YouCam API 請求,因此 API 文件中的所有內容都完全適用:相同的速率限制、錯誤代碼與檔案保留期限。也請參考 API 本身的偵錯指南。

錯誤出現的位置

問題可能出現在三個時點:

失敗位置結束代碼stdoutstderr參見
CLI 在送出前拒絕指令1空錯誤訊息CLI 錯誤
API 拒絕請求1含 status、error 與 error_code 的 JSON空API 請求錯誤
任務執行但失敗0含 "task_status": "error" 的 JSON,data.error 中有代碼,data.error_message 中有說明空任務錯誤

失敗的任務仍以 0 結束,因為 status 請求本身成功了。腳本必須檢查 data.task_status,不能只看結束代碼。

速率限制

API 速率限制適用於每個 youcam 指令:

  • 依 IP 位址: 每 300 秒最多 250 個請求。
  • 依 access token(API key): 每 300 秒最多 250 個請求。
  • 兩個限制都必須符合。違反任一個的請求會得到 429 Too Many Requests,CLI 以代碼 1 結束。
  • 建議節奏約為每秒 5 個請求。

多數指令發送一個 API 請求。使用本地檔案的 run,在任務請求之前,每個檔案也會發送一個 POST /s2s/v2.0/file 請求。輪詢也計入——每秒檢查多個任務會很快用完限制。請每隔數秒輪詢,收到 429 時,請等待並以遞增的延遲重試,而不是立即重試。

CLI 錯誤

這些會在任務請求送出前被攔截,因此不會使用點數。

CLI 錯誤訊息可能原因解法
Not authenticated. Run: youcam auth login <apiKey>, or set YOUCAM_CLI_API_KEY沒有已儲存的 API 金鑰,且 YOUCAM_CLI_API_KEY 未設定或為空執行 youcam auth login <apiKey>,或設定 YOUCAM_CLI_API_KEY
Invalid credentials file at <path>. Re-run: youcam auth login <apiKey>credentials.json 不是有效的 JSON,或 apiKey 為空或不是字串執行 youcam auth login <apiKey>。它會覆蓋該檔案
Can't log out: credentials file at <path> is invalid. Fix or delete it by handyoucam auth logout 發現同樣無效的 credentials.json,且未更動它將檔案修正為 { "apiKey": "<your-api-key>" },然後再次登出,或刪除該檔案
error: required option '--scale <value>' not specified缺少必要選項加上它。youcam run <feature> --help 會列出所有選項
error: option '--scale <value>' argument '9' is invalid. Allowed choices are 1, 2, 4.值不在允許的選項中使用列出的值之一
Invalid value for --page_size: 99 (Too big: expected number to be <=20)值類型錯誤或超出範圍。對 JSON 選項,訊息會指出欄位修正值。JSON 引號請見傳遞 JSON 參數
error: unknown option '--bogus'該選項不存在於此功能,或拼寫錯誤在 --help 中檢查拼寫。選項使用 snake_case,例如 --src_file,不是 --src-file
ENOENT: no such file or directory, open '...'本地檔案路徑錯誤檢查路徑。相對路徑從目前目錄開始。含空格的路徑請加上引號
Unsupported file type "unknown" for ./notes.txt. Supported types: image/jpeg, image/png, video/mp4本地檔案不是 JPG、PNG 或 MP4轉換檔案,或改傳公開網址
Missing task ID. Usage: status <feature> <task_id> (or --task_id <value>)執行 status 時未帶任務 ID傳入 run 印出的 task_id

API 請求錯誤

API 拒絕了請求。CLI 會在 stdout 印出 API 的回應,例如:

{
  "status": 400,
  "error": "This task ID doesn't exist, or the task has expired.",
  "error_code": "InvalidTaskId"
}
狀態error_code可能原因解法
400InvalidTaskId任務 ID 輸入錯誤、屬於另一個功能(例如以 status hair-color 檢查 run enhance 的任務),或超過 30 天,也就是 task_id 的有效期間在 status 中使用與 run 相同的功能名稱。前處理任務請使用 youcam status pre-process <feature> <task_id>。請在啟動任務後 30 天內檢查任務
401InvalidAccessToken已儲存的 API 金鑰錯誤,或已不再有效從 API console 複製金鑰,並再次執行 youcam auth login。金鑰中不要包含用法說明裡的 < >
429—來自您的 IP 位址或 API 金鑰的請求過多放慢速度,並以遞增的延遲重試。見速率限制

任務錯誤

任務已被接受,但 AI 引擎無法處理。youcam status 回傳 "task_status": "error",代碼在 data.error,說明在 data.error_message。請在 API 的錯誤代碼頁面查詢代碼。某些功能有額外的代碼,列在該功能 API 參考頁面的「File Specs & Errors」中,包含其大小、解析度與姿勢限制。

過期的結果連結

結果網址(例如 results.url,或 ai-avatar 的 results.output[].url)在任務成功後可用 2 小時。若已過期,請再次執行 youcam status <feature> <task_id> 取得新的連結;這在任務建立後 30 天內都有效。結果會在 30 天後刪除,因此請在期限前下載您想保留的內容。

取得協助

youcam help
youcam help <command>
youcam <command> <subcommand> --help # 例如 youcam run pre-process --help