ログイン
Lookbook Studio

API で任せる

写真をアップロードして任せ、終わったら結果のファイルを受け取ります。

API で任せた仕事も、画面で任せた仕事と同じようにプロジェクトとして残り、同じ残高から差し引かれます。

  1. キーを作る

    ログインしたあと、左のメニューの「API キー」で作ります。キーは、ワークスペースごとに一人一つです。

    すべてのリクエストは、Authorization: Bearer ヘッダーでキーを送ります。以下のコードは、キーと URL をこの2行から読み込みます。

    shell
    export FLOW_API_KEY="<api_key>"
    export FLOW_URL="https://flow.unblanq.com"
  2. 写真をアップロードする

    写真1枚ごとに1回呼び出します。slot は main_item_reference_images にし、レスポンスの descriptor を集めておきます。

    PNG・JPEG・WebP 形式を、1件につき 6枚まで受け付けます。アップロードした写真は、descriptor の expires_at まで保管されます。

    curl
    curl -X POST \
      "$FLOW_URL/v1/agencies/agency%3Afashion_atelier/actions/fashion_studio_create_product_cuts/uploads" \
      -H "Authorization: Bearer $FLOW_API_KEY" \
      -F "slot=main_item_reference_images" \
      -F "file=@<file>"
  3. 任せる

    集めた descriptor を apparel.main_item_reference_images に入れて送ります。idempotency_key は、自分で決めてこのリクエストに付ける番号です。

    レスポンスの result.run_id で状態を確認し、result.admission.target_id で結果を探します。

    同じ idempotency_key と同じ inputs で24時間以内にもう一度送ると、新しく任せず、最初に任せたときのレスポンスをもう一度返します(deduplicated: true)。inputs が違うと、409で断ります。

    curl
    curl -X POST \
      "$FLOW_URL/v1/agencies/agency%3Afashion_atelier/actions/fashion_studio_create_product_cuts/runs" \
      -H "Authorization: Bearer $FLOW_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "inputs": {
          "schema_version": "fashion_studio_create_product_cuts.input.v12",
          "generation_mode": "initial",
          "initial_source": {"mode": "uploads"},
          "product": {"title": "トラックスーツ", "target_gender": "unisex"},
          "apparel": {
            "main_item_title": "トラックスーツ",
            "main_item_reference_images": [<descriptor>, <descriptor>]
          },
          "model": {"selection_mode": "auto", "pose_mode": "auto"},
          "space": {"mode": "auto"},
          "outputs": {
            "model_editorial": {"enabled": true, "count": 4},
            "product_detail": {"enabled": true, "count": 4, "style": "styled_flat_lay"}
          }
        },
        "idempotency_key": "request-001"
      }'
  4. 状態を確認する

    終わるまで数秒ごとに呼び出します。status が succeeded・failed・cancelled のどれかになれば終わりです。

    failed なら、public_errors に理由が入ります。

    curl
    curl "$FLOW_URL/v1/runs/<run_id>" \
      -H "Authorization: Bearer $FLOW_API_KEY"
  5. 結果を受け取る

    結果はプロジェクトとして残ります。まず一覧で、record_key が target_id の項目の record_id を探します。最初のページになければ、レスポンスの next_cursor を cursor に入れて次のページを見ます。

    その record_id で読み込むと、結果のファイルの一覧が result.outputs で返ってきます。受け取るファイルの record_id と revision_id を選びます。record_id の代わりに target_id を入れないでください。

    ダウンロードには、プロジェクトの record_id、選んだファイルの record_id(output_record_id)と revision_id を入れます。レスポンスの result.download_url を同じキーで呼び出すと、ファイルを受け取れます。

    curl
    # 1. 一覧:record_key が target_id の項目の record_id
    curl -X POST \
      "$FLOW_URL/v1/agencies/agency%3Afashion_atelier/actions/fashion_studio_list_products/runs" \
      -H "Authorization: Bearer $FLOW_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"inputs": {"relation": "owned", "limit": 50}}'
    
    # 2. 読み込み:結果のファイルの一覧は result.outputs
    curl -X POST \
      "$FLOW_URL/v1/agencies/agency%3Afashion_atelier/actions/fashion_studio_read_product/runs" \
      -H "Authorization: Bearer $FLOW_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"inputs": {"record_id": "<record_id>"}}'
    
    # 3. ダウンロード:ファイルの URL は result.download_url
    curl -X POST \
      "$FLOW_URL/v1/agencies/agency%3Afashion_atelier/actions/fashion_studio_download_product_version/runs" \
      -H "Authorization: Bearer $FLOW_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "inputs": {
          "record_id": "<record_id>",
          "output_record_id": "<output_record_id>",
          "revision_id": "<revision_id>",
          "output_format": "png"
        }
      }'
    
    # 4. ファイルの受け取り:$FLOW_URL のあとに download_url
    curl -L "$FLOW_URL<download_url>" \
      -H "Authorization: Bearer $FLOW_API_KEY" \
      -o <filename>

任せるときに入れるものfashion_studio_create_product_cuts

名前形式必須説明
apparel object いいえ メインアイテムの名前と写真で、新しいプロジェクトには必ず入れます。
camera object いいえ カメラの種類(camera_class)とフィルムスタイル(film_profile)です。送らない場合は dslr です。
composition_preferences object | null いいえ アスペクト比(aspect_ratio)、フォーカス(focus)、フレーミング(framing)を選びます。送らない場合は auto です。
design_text object いいえ ストーリーカットとクリエイティブカットに入れる文字の言語を、language_direction に文章で書きます。
environment_setting object いいえ 天気(weather)と時間帯(time_of_day)です。送らない場合は晴れ、午前遅め〜午後早めです。
generation_mode enum: "initial", "additional" はい 新しいプロジェクトを作るときは initial を送ります。
initial_source object | null いいえ プロジェクトを何から始めるかで、新しいプロジェクトには必ず入れます。アップロードした写真から始めるなら {"mode": "uploads"} を送ります。
model object いいえ カットに登場するモデルとポーズで、新しいプロジェクトには必ず入れます。auto なら、自分が作成したモデルと共有されたモデル(管理者は、管理する人のモデルも)の中から対象の性別に合うモデルを選び、ポーズも自動で決めます。
outputs object | null いいえ 解像度(resolution_tier)とカットの種類ごとの枚数です。送る場合は、model_editorial・product_detail・story_card・creative のうち1つ以上を enabled でオンにします。
product object はい 商品名(title)と対象の性別(target_gender:female・male・unisex)です。
round_request_id stringminLength: 1 · maxLength: 256 はい このリクエストの番号です。
schema_version const: "fashion_studio_create_product_cuts.input.v12" はい 入力形式のバージョンです。記載の値をそのまま送ります。
smart_retouch object いいえ スマートレタッチです。on(標準)なら、モデルカットとクリエイティブカットを、カットごとに補正済みの1枚で受け取ります。
smart_retry object いいえ スマート再試行です。オン(enabled)にすると、結果に問題があるカットを作り直し、そのたびに料金が加わります。
space object いいえ 撮影空間で、新しいプロジェクトには必ず入れます。auto なら自動で決めます。

product.product_version_id、product.product_id と round_request_id は送らなくてもかまいません。Flow が idempotency_key をもとに入れます。

Lookbook Studio

今すぐ任せる