> ## Documentation Index
> Fetch the complete documentation index at: https://comfyuiwiki.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Comfy Router でテキストから動画を使用する

> Comfy Router 経由で moonvalley/text-to-video を呼び出します。エンドポイント、リクエストの形状、Router が返すレスポンスについて説明します。

`moonvalley/text-to-video` の API リファレンスです。Comfy Router が Moonvalley から提供します。

## クイックスタート

[Comfy ワークスペース](https://platform.comfy.org/profile/api-keys?onboarding=router)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python と TypeScript のスニペットは Comfy SDK（`pip install comfy-sdk` および `npm install @comfyorg/sdk`）を使用しており、cURL のスニペットは同じ呼び出しを生の HTTP で行うものです。

**モデル ID:** `moonvalley/text-to-video`

**エンドポイント:** `POST https://api.comfy.org/v2/models/moonvalley/text-to-video`

<Tabs defaultTabIndex={1}>
  <Tab title="結果を待つ">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # SDK は自動的に冪等性キーを作成し、自動リトライのために再利用します。
      with Comfy() as client:
          result = client.models.run(
              "moonvalley/text-to-video",
              {
                  "prompt_text": "a single red maple leaf",
              },
          )

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 環境変数から COMFY_API_KEY を読み取ります。
      // SDK は自動的に冪等性キーを作成し、自動リトライのために再利用します。
      const { data } = await comfy.models.run("moonvalley/text-to-video", {
        prompt_text: "a single red maple leaf",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/moonvalley/text-to-video \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt_text\": \"a single red maple leaf\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="キューに送信して後で収集">
    同じボディを `POST https://api.comfy.org/v2/models/moonvalley/text-to-video/requests` に送信します。Router は実行が受け付けられ次第 `201` と `request_id` を返し、結果は準備が整った時点で、このプロセスからでも別のプロセスからでも収集できます。ステータス、キャンセル、結果の収集については [キュー配信](/ja/development/comfy-router/queue) で詳しく説明しています。

    <CodeGroup>
      ```python Python theme={null}
      import asyncio
      from comfy_sdk import AsyncComfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライのために再利用します。
      async def main():
          async with AsyncComfy() as client:
              handle = await client.models.submit(
                  "moonvalley/text-to-video",
                  {
                      "prompt_text": "a single red maple leaf",
                  },
              )
              print("request_id:", handle.request_id)  # モデル ID と合わせて、別のプロセスに必要なものはこれだけです

              # サーバーが指定する Retry-After だけ待機しながら、リクエストが完了するまでポーリングします。
              async for update in handle.iter_events():
                  print(update.status, update.queue_position)

              # プロバイダー自身のペイロードで、models.run() が返すのと同じ値です。
              # 失敗またはキャンセルされたリクエストは、ここで型付きの Router エラーを発生させます。
              result = await handle.get()

          print(result)

      asyncio.run(main())
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // 環境変数から COMFY_API_KEY を読み取ります。
      // 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライのために再利用します。
      const handle = await comfy.models.submit("moonvalley/text-to-video", {
        prompt_text: "a single red maple leaf",
      });
      console.log("requestId:", handle.requestId); // モデル ID と合わせて、別のプロセスに必要なものはこれだけです

      // サーバーが指定する Retry-After だけ待機しながら、リクエストが完了するまでポーリングします。
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // models.run() が返すのと同じ結果です。失敗またはキャンセルされたリクエストはここで reject されます。
      const result = await handle.get();

      console.log(result.data);
      ```

      ```bash cURL theme={null}
      # 1. 送信します。Router は request_id、status_url、response_url、cancel_url とともに 201 を返します。
      curl https://api.comfy.org/v2/models/moonvalley/text-to-video/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt_text\": \"a single red maple leaf\"}"

      # 2. 各レスポンスが指定する Retry-After 秒だけ待機しながら、ステータスが COMPLETED になるまでポーリングします。
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/moonvalley/text-to-video/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. 収集します。モデルのネイティブ出力とともに 200、実行中はステータスボディとともに 202 を返します。
      curl https://api.comfy.org/v2/models/moonvalley/text-to-video/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="image_url" type="string" />

<ParamField body="inference_params" type="object" />

<ParamField body="inference_params.guidance_scale" type="number" default="10">
  生成を制御するためのガイダンススケール

  形式: `float`
</ParamField>

<ParamField body="inference_params.height" type="integer" default="1080">
  生成されるビデオの高さ（ピクセル単位）
</ParamField>

<ParamField body="inference_params.negative_prompt" type="string">
  ネガティブプロンプトのテキスト
</ParamField>

<ParamField body="inference_params.seed" type="integer" default="9">
  生成用のランダムシード（デフォルト: ランダム）
</ParamField>

<ParamField body="inference_params.steps" type="integer" default="80">
  ノイズ除去ステップ数
</ParamField>

<ParamField body="inference_params.use_negative_prompts" type="boolean" default="true">
  ネガティブプロンプトを使用するかどうか
</ParamField>

<ParamField body="inference_params.width" type="integer" default="1920">
  生成されるビデオの幅（ピクセル単位）
</ParamField>

<ParamField body="prompt_text" type="string" />

<ParamField body="webhook_url" type="string" />

スキーマから生成され、Router は `GET /v2/models/moonvalley/text-to-video/openapi.json` で配信します。これは、リクエストがプロバイダーに到達する前に呼び出しを検証する際に使用するのと同じドキュメントです。

### 出力

<ResponseField name="error" type="object" />

<ResponseField name="frame_conditioning" type="object" />

<ResponseField name="id" type="string" />

<ResponseField name="inference_params" type="object" />

<ResponseField name="meta" type="object" />

<ResponseField name="model_params" type="object" />

<ResponseField name="output_url" type="string" required />

<ResponseField name="prompt_text" type="string" />

<ResponseField name="status" type="string" required />

## 例

### 入力

```json theme={null}
{
  "prompt_text": "a single red maple leaf"
}
```

### 出力

```json theme={null}
{
  "id": "018f2c7a-4b1e-7c3d-9a05-6e2f8b41d0c9",
  "output_url": "https://example.invalid/moonvalley/prompts/output.mp4",
  "prompt_text": "a single red maple leaf falling onto still water",
  "status": "completed"
}
```

## 出荷前の確認

SDK は `Idempotency-Key` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

リクエストが失敗すると、Router は理由を説明する `X-Comfy-Error-Type` レスポンスヘッダーを送信します。`422` は、プロバイダーを呼び出す前に Router が入力を拒否したことを意味し、`413` はリクエスト本文が Router の受け入れ可能なサイズを超えていたことを意味します。生成されたアセットは [結果 URL の有効期限](/ja/development/comfy-router/reference#結果アセット) があるため、早めにダウンロードしてください。

上記のフィールド説明に記載されているサイズ制限は、プロバイダーの仕様から引用した、そのフィールドに対するプロバイダー自身の上限です。Router はリクエスト本文全体に対して別の上限を適用し、base64 エンコードされたメディアもこれにカウントされます。[リクエスト本文のサイズ](/ja/development/comfy-router/limitations) を参照してください。

このページは、Comfy Router 経由で呼び出す 1 つのパートナーモデルについて説明しています。同じ `comfy-sdk` / `@comfyorg/sdk` パッケージには、Comfy Cloud 上で ComfyUI のワークフローグラフ全体を実行するための 2 つ目のクライアントも含まれています: `Comfy(api_key=...)` / `new Comfy({ apiKey })`、および `client.workflows`、`client.assets`、`client.jobs`。[Comfy SDKs](/ja/development/api-development/sdks) を参照してください。

<CardGroup cols={3}>
  <Card title="ヘッダー" icon="list" href="/ja/development/comfy-router/headers">
    認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。
  </Card>

  <Card title="Router API の利用" icon="code" href="/ja/development/comfy-router/api">
    モデルの検出、バリデーションエラー、リトライ、課金。
  </Card>

  <Card title="制限事項" icon="triangle-exclamation" href="/ja/development/comfy-router/limitations">
    Router が現在対応していないことと、代替手段。
  </Card>
</CardGroup>
