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

# 使用 Comfy Router 调用 Gemini Omni Flash Preview

> 通过 Comfy Router 调用 gemini-interactions/gemini-omni-flash-preview：endpoint、请求形状以及 Router 返回的响应。

`gemini-interactions/gemini-omni-flash-preview` 的 API 参考文档，由 Comfy Router 从 Gemini Interactions 提供。

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 代码片段使用 Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）；cURL 代码片段则是通过原始 HTTP 发起的同一调用。

**模型 ID：** `gemini-interactions/gemini-omni-flash-preview`

**端点：** `POST https://api.comfy.org/v2/models/gemini-interactions/gemini-omni-flash-preview`

<Tabs>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      with Comfy() as client:
          result = client.models.run(
              "gemini-interactions/gemini-omni-flash-preview",
              {
                  "input": "Reply with the single word: ok",
                  "stream": False,
              },
          )

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      const { data } = await comfy.models.run("gemini-interactions/gemini-omni-flash-preview", {
        input: "Reply with the single word: ok",
        stream: false,
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/gemini-interactions/gemini-omni-flash-preview \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": \"Reply with the single word: ok\", \"stream\": false}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Queue and collect later">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = client.models.submit(
              "gemini-interactions/gemini-omni-flash-preview",
              {
                  "input": "Reply with the single word: ok",
                  "stream": False,
              },
          )
          print("request_id:", handle.request_id)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      const handle = await comfy.models.submit("gemini-interactions/gemini-omni-flash-preview", {
        input: "Reply with the single word: ok",
        stream: false,
      });
      console.log("requestId:", handle.requestId); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

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

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and cancel_url.
      curl https://api.comfy.org/v2/models/gemini-interactions/gemini-omni-flash-preview/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input\": \"Reply with the single word: ok\", \"stream\": false}"

      # 2. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/gemini-interactions/gemini-omni-flash-preview/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/gemini-interactions/gemini-omni-flash-preview/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## 结构

### 输入

<ParamField body="input" type="object" required>
  可以是提示词字符串，也可以是类型化内容部分的数组（文本、图像、音频、视频、文档）。
</ParamField>

<ParamField body="model" type="string">
  Gemini 模型标识符（例如 `gemini-omni-flash-preview`）。在 Comfy Router 路由 `POST /v2/models/gemini-interactions/{model}` 上，它由路径提供，可以省略。此操作所服务的拼写（即 Comfy Router 以 `gemini-interactions/<model>` 寻址的集合）为 gemini-omni-flash-preview 和 gemini-omni-1.1-flash（supportedGeminiInteractionModels）；这里将它们逐一写出，而不是限制为枚举，因为代理会自行校验模型，并对它不服务的拼写返回自己的 400。
</ParamField>

<ParamField body="previous_interaction_id" type="string">
  先前存储的交互 ID，可实现有状态的多轮视频编辑。
</ParamField>

由 Router 在 `GET /v2/models/gemini-interactions/gemini-omni-flash-preview/openapi.json` 提供的 schema 生成，也就是它在请求到达提供商之前用于校验调用的同一份文档。

### 输出

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

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

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

<ResponseField name="status" type="string" required>
  在 Router 响应中始终为 `completed`。提供商的其他状态（`in_progress`、`requires_action`、`failed`、`cancelled`、`incomplete`、`budget_exceeded`）不会以 200 的形式通过 Router 到达调用方；它们会作为携带提供商响应体的 Comfy Router 错误返回。

  可能的值：`completed`
</ResponseField>

<ResponseField name="steps" type="object[]" required>
  交互时间线，按顺序排列。这里从 `GeminiInteraction` 上无类型的 `steps` 收窄而来，以便输出叶子可寻址；提供商会不断添加步骤类型，因此条目为 `additionalProperties: true`，只声明 Router 调用方会读取的字段。
</ResponseField>

<ResponseField name="steps[].content" type="object[]">
  此步骤的类型化内容块。
</ResponseField>

<ResponseField name="steps[].content[].data" type="string">
  内联交付的媒体块上，以 Base64 编码的内联媒体。Google 将内联媒体上限设为 4 MB，超过则要求使用 `delivery: uri`。
</ResponseField>

<ResponseField name="steps[].content[].mime_type" type="string">
  媒体块上 `data` 或 `uri` 的媒体类型。
</ResponseField>

<ResponseField name="steps[].content[].text" type="string">
  已生成的文本。出现在 `text` 块上，这正是每夜 Router SDK 用例所断言的叶子：具体是在 `model_output` 步骤上（`steps[type=model_output].content[].text`）。
</ResponseField>

<ResponseField name="steps[].content[].type" type="string">
  块类型：`text`、`image`、`audio`、`video` 或 `document`。
</ResponseField>

<ResponseField name="steps[].content[].uri" type="string">
  对带外交付的媒体的引用，由调用方从其所指明的 URI 获取。
</ResponseField>

<ResponseField name="steps[].type" type="string">
  步骤类型。`model_output` 是已生成的回答；`user_input` 是检索路由回显的调用方自身轮次；`thought` 是内部推理。工具步骤（`function_call`、`function_result`、`code_execution_call`、`google_search_call` 等）是开放式的，Google 会不断添加。
</ResponseField>

<ResponseField name="usage" type="object">
  Gemini 交互的 token 用量。
</ResponseField>

<ResponseField name="usage.input_tokens_by_modality" type="object[]">
  单一模态的 token 计数。
</ResponseField>

<ResponseField name="usage.input_tokens_by_modality[].modality" type="string">
  `text`、`image`、`audio`、`video`、`document` 之一。
</ResponseField>

<ResponseField name="usage.input_tokens_by_modality[].tokens" type="integer" />

<ResponseField name="usage.output_tokens_by_modality" type="object[]">
  单一模态的 token 计数。
</ResponseField>

<ResponseField name="usage.output_tokens_by_modality[].modality" type="string">
  `text`、`image`、`audio`、`video`、`document` 之一。
</ResponseField>

<ResponseField name="usage.output_tokens_by_modality[].tokens" type="integer" />

<ResponseField name="usage.total_cached_tokens" type="integer" />

<ResponseField name="usage.total_input_tokens" type="integer" />

<ResponseField name="usage.total_output_tokens" type="integer" />

<ResponseField name="usage.total_thought_tokens" type="integer" />

<ResponseField name="usage.total_tokens" type="integer" />

## 示例

### 输入

```json theme={null}
{
  "input": "Reply with the single word: ok",
  "stream": false
}
```

### 输出

```json theme={null}
{
  "id": "interactions/3f6c1a90-2b47-4d18-9a55-7c0e8b21d4f3",
  "object": "interaction",
  "status": "completed",
  "steps": [
    {
      "content": [
        {
          "text": "ok",
          "type": "text"
        }
      ],
      "type": "model_output"
    }
  ],
  "usage": {
    "input_tokens_by_modality": [
      {
        "modality": "text",
        "tokens": 9
      }
    ],
    "output_tokens_by_modality": [
      {
        "modality": "text",
        "tokens": 2
      }
    ],
    "total_cached_tokens": 0,
    "total_input_tokens": 9,
    "total_output_tokens": 2,
    "total_thought_tokens": 0,
    "total_tokens": 11
  }
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/quickstart">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/quickstart">
    模型发现、校验错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
