> ## 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 调用 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?onboarding=router)中创建一个密钥，并将其导出为 `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 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(
              "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";

      // 从环境中读取 COMFY_API_KEY。
      // SDK 会自动创建一个幂等键，并在自动重试时复用它。
      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="排队并稍后收集">
    相同的请求体，发送到 `POST https://api.comfy.org/v2/models/gemini-interactions/gemini-omni-flash-preview/requests`。一旦运行被接纳，Router 会立即返回 `201` 和一个 `request_id`，结果准备就绪后再行收集，可以在本进程或另一个进程中完成。[队列投递](/zh/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(
                  "gemini-interactions/gemini-omni-flash-preview",
                  {
                      "input": "Reply with the single word: ok",
                      "stream": False,
                  },
              )
              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("gemini-interactions/gemini-omni-flash-preview", {
        input: "Reply with the single word: ok",
        stream: false,
      });
      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 返回 201，带有 request_id、status_url、response_url 和 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. 轮询直到状态为 COMPLETED，每个响应指定的 Retry-After 秒数都要等待。
      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. 收集。返回 200 时带有模型的原生输出；仍在运行时则返回 202 和状态正文。
      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>

## Schema

### 输入

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

<ParamField body="model" type="string">
  Gemini 模型标识符：`gemini-omni-1.1-flash`（已正式发布），或已弃用的 `gemini-omni-flash-preview`。在 Comfy Router 路由 `POST /v2/models/gemini-interactions/{model}` 上，它由路径提供，可以省略。此操作所服务的正是这两种拼写，即 Comfy Router 以 `gemini-interactions/<model>` 寻址的集合（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 在调用提供商之前就拒绝了输入，`413` 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载，因为[结果 URL 会过期](/zh/development/comfy-router/reference#结果资产)。

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](/zh/development/comfy-router/limitations)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](/zh/development/api-development/sdks)。

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

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

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