> ## 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 で Chat Completions を使用する

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

Openrouter から Comfy Router によって提供される `openrouter/chat-completions` の API リファレンスです。

**入力：** テキスト, 画像 · **出力：** テキスト

## リクエストのセットアップ

[お使いの Comfy ワークスペース](https://platform.comfy.org/profile/api-keys?onboarding=router)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python の場合は `pip install comfy-sdk` を実行します。TypeScript の場合は `npm install @comfyorg/sdk` を実行します。cURL は生の HTTP を使用します。

**モデル ID:** `openrouter/chat-completions`

**エンドポイント:** `POST https://api.comfy.org/v2/models/openrouter/chat-completions`

> [!NOTE]
>
> このモデルには実行可能なリクエスト例がありません。以下の入力ドキュメントからボディを構築し、[Router クイックスタート](https://docs.comfy.org/ja/development/comfy-router/quickstart.md)で使用してください。

## スキーマ

### 入力

**cache\_control** `object`

自動プロンプトキャッシュを有効にします。トップレベルで設定すると、リクエスト内の最後のキャッシュ可能なブロックにキャッシュブレークポイントが自動的に適用されます。現在は Anthropic Claude モデルでサポートされています。

**cache\_control.ttl** `string`

指定可能な値: `5m`、`1h`

**cache\_control.type** `string` *required*

指定可能な値: `ephemeral`

**debug** `object`

リクエストの変換を検査するためのデバッグオプション（ストリーミングのみ）

**debug.echo\_upstream\_body** `boolean`

true の場合、変換後の上流リクエストボディをストリーム開始時のデバッグチャンクに含めます。ストリーミングモードでのみ動作します。

**frequency\_penalty** `number`

頻度ペナルティ（-2.0 から 2.0）

形式: `double`

**image\_config** `object | string | number | object[]`

**logit\_bias** `object`

トークンの logit バイアス調整

**logprobs** `boolean`

対数確率を返します

**max\_completion\_tokens** `integer`

補完の最大トークン数

**max\_tokens** `integer`

最大トークン数（非推奨。max\_completion\_tokens を使用してください）。注意: 一部のプロバイダーでは最小 16 が強制されます。

**messages** `object[]` *required*

会話のメッセージのリスト

**metadata** `object`

追加のオブジェクト情報のためのキーと値のペア（最大 16 ペア、キーは 64 文字、値は 512 文字）

**modalities** \`\`text`, `image`, `audio`[]`

レスポンスの出力モダリティ。サポートされる値は "text"、"image"、"audio" です。

**model** `string`

補完に使用するモデル

**models** `string[]`

補完に使用するモデル

**parallel\_tool\_calls** `boolean`

ツール使用時に並列関数呼び出しを有効にするかどうか。true の場合、モデルは 1 回のレスポンスで複数のツール呼び出しを生成することがあります。

**plugins** `object[]`

このリクエストで有効にするプラグインとその設定。

**presence\_penalty** `number`

存在ペナルティ（-2.0 から 2.0）

形式: `double`

**provider** `object`

複数のモデルプロバイダーが利用可能な場合に、ルーティングの優先設定を任意で指定します。

**provider.allow\_fallbacks** `boolean`

バックアッププロバイダーによるリクエスト処理を許可するかどうか

* true:（デフォルト）プライマリプロバイダー（または "order" で指定したカスタムプロバイダー）が利用できない場合、次に最適なプロバイダーを使用します。
* false: プライマリまたはカスタムプロバイダーのみを使用し、利用できない場合は上流のエラーを返します。

**provider.data\_collection** ``deny`, `allow``

データ収集の設定。要件を満たす利用可能なモデルプロバイダーがない場合、リクエストはエラーを返します。

* allow:（デフォルト）ユーザーデータを一時的でない形で保存し、それを学習に使用する可能性があるプロバイダーを許可します。
* deny: ユーザーデータを収集しないプロバイダーのみを使用します。

**provider.enforce\_distillable\_text** `boolean`

テキスト蒸留を許可しているモデルのみにルーティングを制限するかどうか。true の場合、作者が蒸留を許可しているモデルのみが使用されます。

**provider.ignore** \`\`AkashML`, `AI21`, `AionLabs`, `Alibaba`, `Ambient`, `Baidu`, `Amazon Bedrock`, `Amazon Nova`, `Anthropic`, `Arcee AI`, `AtlasCloud`, `Avian`, `Azure`, `BaseTen`, `BytePlus`, `Black Forest Labs`, `Cerebras`, `Chutes`, `Cirrascale`, `Clarifai`, `Cloudflare`, `Cohere`, `Crucible`, `Crusoe`, `DeepInfra`, `DeepSeek`, `DekaLLM`, `Featherless`, `Fireworks`, `Friendli`, `GMICloud`, `Google`, `Google AI Studio`, `Groq`, `Hyperbolic`, `Inception`, `Inceptron`, `InferenceNet`, `Ionstream`, `Infermatic`, `Io Net`, `Inflection`, `Liquid`, `Mara`, `Mancer 2`, `Minimax`, `ModelRun`, `Mistral`, `Modular`, `Moonshot AI`, `Morph`, `NCompass`, `Nebius`, `Nex AGI`, `NextBit`, `Novita`, `Nvidia`, `OpenAI`, `OpenInference`, `Parasail`, `Poolside`, `Perceptron`, `Perplexity`, `Phala`, `Recraft`, `Reka`, `Relace`, `SambaNova`, `Seed`, `SiliconFlow`, `Sourceful`, `StepFun`, `Stealth`, `StreamLake`, `Switchpoint`, `Together`, `Upstage`, `Venice`, `WandB`, `Xiaomi`, `xAI`, `Z.AI`, `FakeProvider` | string[]`

無視するプロバイダーのスラッグのリスト。指定した場合、このリストはこのリクエストに対してアカウント全体で無視するプロバイダー設定とマージされます。

**provider.max\_price** `object`

このリクエストに対して支払う最大価格を指定するオブジェクト。プロンプトと補完の 100 万トークンあたりの USD 価格です。

**provider.max\_price.audio** `string`

100 万プロンプトトークンあたりの価格

**provider.max\_price.completion** `string`

100 万プロンプトトークンあたりの価格

**provider.max\_price.image** `string`

100 万プロンプトトークンあたりの価格

**provider.max\_price.prompt** `string`

100 万プロンプトトークンあたりの価格

**provider.max\_price.request** `string`

100 万プロンプトトークンあたりの価格

**provider.only** \`\`AkashML`, `AI21`, `AionLabs`, `Alibaba`, `Ambient`, `Baidu`, `Amazon Bedrock`, `Amazon Nova`, `Anthropic`, `Arcee AI`, `AtlasCloud`, `Avian`, `Azure`, `BaseTen`, `BytePlus`, `Black Forest Labs`, `Cerebras`, `Chutes`, `Cirrascale`, `Clarifai`, `Cloudflare`, `Cohere`, `Crucible`, `Crusoe`, `DeepInfra`, `DeepSeek`, `DekaLLM`, `Featherless`, `Fireworks`, `Friendli`, `GMICloud`, `Google`, `Google AI Studio`, `Groq`, `Hyperbolic`, `Inception`, `Inceptron`, `InferenceNet`, `Ionstream`, `Infermatic`, `Io Net`, `Inflection`, `Liquid`, `Mara`, `Mancer 2`, `Minimax`, `ModelRun`, `Mistral`, `Modular`, `Moonshot AI`, `Morph`, `NCompass`, `Nebius`, `Nex AGI`, `NextBit`, `Novita`, `Nvidia`, `OpenAI`, `OpenInference`, `Parasail`, `Poolside`, `Perceptron`, `Perplexity`, `Phala`, `Recraft`, `Reka`, `Relace`, `SambaNova`, `Seed`, `SiliconFlow`, `Sourceful`, `StepFun`, `Stealth`, `StreamLake`, `Switchpoint`, `Together`, `Upstage`, `Venice`, `WandB`, `Xiaomi`, `xAI`, `Z.AI`, `FakeProvider` | string[]`

許可するプロバイダーのスラッグのリスト。指定した場合、このリストはこのリクエストに対するアカウント全体の許可プロバイダー設定とマージされます。

**provider.order** \`\`AkashML`, `AI21`, `AionLabs`, `Alibaba`, `Ambient`, `Baidu`, `Amazon Bedrock`, `Amazon Nova`, `Anthropic`, `Arcee AI`, `AtlasCloud`, `Avian`, `Azure`, `BaseTen`, `BytePlus`, `Black Forest Labs`, `Cerebras`, `Chutes`, `Cirrascale`, `Clarifai`, `Cloudflare`, `Cohere`, `Crucible`, `Crusoe`, `DeepInfra`, `DeepSeek`, `DekaLLM`, `Featherless`, `Fireworks`, `Friendli`, `GMICloud`, `Google`, `Google AI Studio`, `Groq`, `Hyperbolic`, `Inception`, `Inceptron`, `InferenceNet`, `Ionstream`, `Infermatic`, `Io Net`, `Inflection`, `Liquid`, `Mara`, `Mancer 2`, `Minimax`, `ModelRun`, `Mistral`, `Modular`, `Moonshot AI`, `Morph`, `NCompass`, `Nebius`, `Nex AGI`, `NextBit`, `Novita`, `Nvidia`, `OpenAI`, `OpenInference`, `Parasail`, `Poolside`, `Perceptron`, `Perplexity`, `Phala`, `Recraft`, `Reka`, `Relace`, `SambaNova`, `Seed`, `SiliconFlow`, `Sourceful`, `StepFun`, `Stealth`, `StreamLake`, `Switchpoint`, `Together`, `Upstage`, `Venice`, `WandB`, `Xiaomi`, `xAI`, `Z.AI`, `FakeProvider` | string[]`

プロバイダーのスラッグの順序付きリスト。ルーターは、このリストのうちリクエストされたモデルをサポートするサブセットの最初のプロバイダーを使用しようとし、利用できない場合は次のプロバイダーにフォールバックします。利用可能なプロバイダーがない場合、リクエストはエラーメッセージとともに失敗します。

**provider.preferred\_max\_latency** `number | object`

希望する最大レイテンシ (秒単位)。数値 (p50 に適用) またはパーセンタイル別のしきい値を持つオブジェクトを指定できます。しきい値を超えるエンドポイントも引き続き使用される可能性がありますが、ルーティングでは優先度が下がります。フォールバックモデルを使用する場合、しきい値を満たしていればプライマリモデルの代わりにフォールバックモデルが使用されることがあります。

**provider.preferred\_min\_throughput** `number | object`

希望する最小スループット (1 秒あたりのトークン数)。数値 (p50 に適用) またはパーセンタイル別のしきい値を持つオブジェクトを指定できます。しきい値を下回るエンドポイントも引き続き使用される可能性がありますが、ルーティングでは優先度が下がります。フォールバックモデルを使用する場合、しきい値を満たしていればプライマリモデルの代わりにフォールバックモデルが使用されることがあります。

**provider.quantizations** \`\`int4`, `int8`, `fp4`, `fp6`, `fp8`, `fp16`, `bf16`, `fp32`, `unknown`[]`

プロバイダーをフィルタする量子化レベルのリスト。

**provider.require\_parameters** `boolean`

指定したパラメータをサポートするプロバイダーのみにフィルタするかどうか。この設定を省略するか false に設定した場合、プロバイダーはサポートするパラメータのみを受け取り、それ以外は無視します。

**provider.sort** \`\`price`, `throughput`, `latency`, `exacto` | object`

このリクエストで使用する並び替え戦略 ("order" が指定されていない場合)。設定すると、負荷分散は行われません。

**provider.zdr** `boolean`

ルーティングを ZDR (Zero Data Retention、データ保持ゼロ) エンドポイントのみに制限するかどうか。true の場合、プロンプトを保持しないエンドポイントのみが使用されます。

**reasoning** `object`

推論モデルの構成オプション

**reasoning.effort** ``xhigh`, `high`, `medium`, `low`, `minimal`, `none``

推論モデルの推論にかける労力を制約します

**reasoning.summary** `string`

指定可能な値: `auto`、`concise`、`detailed`

**response\_format** `object`

レスポンスフォーマットの構成

**route** `object`

任意の型

**seed** `integer`

決定論的な出力のためのランダムシード

**service\_tier** ``auto`, `default`, `flex`, `priority`, `scale``

このリクエストの処理に使用するサービスティア。

**session\_id** `string`

可観測性のために関連するリクエスト (会話やエージェントワークフローなど) をグループ化するための一意の識別子。リクエストボディと x-session-id ヘッダーの両方で指定された場合、ボディの値が優先されます。最大 256 文字。

**stop** `string | string[] | object`

停止シーケンス (最大 4 個)

**stop\_server\_tools\_when** `object[]`

server-tool エージェントループの停止条件。いずれかの条件が発火するとループが停止します (OR ロジック)。設定すると、`max_tool_calls` を上書きします。

**stream** `boolean` (default: false)

ストリーミングレスポンスを有効にする

**stream\_options** `object`

ストリーミングの構成オプション

**stream\_options.include\_usage** `boolean`

Deprecated: このフィールドは効果がありません。完全な使用状況の詳細は常に含まれます。

**temperature** `number`

サンプリング温度 (0-2)

フォーマット: `double`

**tool\_choice** \`\`none`|`auto`|`required` | object`

ツール選択の設定

**tools** `object[]`

関数呼び出しで利用可能なツール

**top\_logprobs** `integer`

返す上位ログ確率の数 (0-20)

**top\_p** `number`

ニュークリアスサンプリングパラメータ (0-1)

フォーマット: `double`

**trace** `object`

可観測性とトレーシングのためのメタデータ。既知のキー (trace\_id、trace\_name、span\_name、generation\_name、parent\_span\_id) は特別に処理されます。追加のキーはカスタムメタデータとして、設定されたブロードキャスト先にそのまま渡されます。

**trace.generation\_name** `string`

**trace.parent\_span\_id** `string`

**trace.span\_name** `string`

**trace.trace\_id** `string`

**trace.trace\_name** `string`

**user** `string`

一意のユーザー識別子

Router が `GET /v2/models/openrouter/chat-completions/openapi.json` で提供するスキーマ、つまりリクエストがプロバイダーに到達する前に呼び出しを検証するのと同じドキュメントから生成済みです。

### 出力

**choices** `object[]` *required*

補完候補のリスト

**choices\[].finish\_reason** `string` *required*

指定可能な値: `tool_calls`、`stop`、`length`、`content_filter`、`error`

**choices\[].index** `integer` *required*

候補のインデックス

**choices\[].logprobs** `object`

補完の対数確率

**choices\[].logprobs.content** `object[]` *required*

コンテンツトークンの対数確率

**choices\[].logprobs.content\[].bytes** `integer[]` *required*

トークンの UTF-8 バイト列

**choices\[].logprobs.content\[].logprob** `number` *required*

トークンの対数確率

形式: `double`

**choices\[].logprobs.content\[].token** `string` *required*

トークン

**choices\[].logprobs.content\[].top\_logprobs** `object[]` *required*

確率付きの上位代替トークン

**choices\[].logprobs.content\[].top\_logprobs\[].bytes** `integer[]` *required*

**choices\[].logprobs.content\[].top\_logprobs\[].logprob** `number` *required*

形式: `double`

**choices\[].logprobs.content\[].top\_logprobs\[].token** `string` *required*

**choices\[].logprobs.refusal** `object[]`

拒否トークンの対数確率

**choices\[].logprobs.refusal\[].bytes** `integer[]` *required*

トークンの UTF-8 バイト列

**choices\[].logprobs.refusal\[].logprob** `number` *required*

トークンの対数確率

形式: `double`

**choices\[].logprobs.refusal\[].token** `string` *required*

トークン

**choices\[].logprobs.refusal\[].top\_logprobs** `object[]` *required*

確率付きの上位代替トークン

**choices\[].logprobs.refusal\[].top\_logprobs\[].bytes** `integer[]` *required*

**choices\[].logprobs.refusal\[].top\_logprobs\[].logprob** `number` *required*

形式: `double`

**choices\[].logprobs.refusal\[].top\_logprobs\[].token** `string` *required*

**choices\[].message** `object` *required*

リクエストとレスポンスのアシスタントメッセージ

**choices\[].message.audio** `object`

オーディオ出力データまたは参照

**choices\[].message.audio.data** `string`

Base64 エンコードされたオーディオデータ

**choices\[].message.audio.expires\_at** `integer`

オーディオの有効期限タイムスタンプ

**choices\[].message.audio.id** `string`

オーディオ出力の識別子

**choices\[].message.audio.transcript** `string`

オーディオの文字起こし

**choices\[].message.content** `string | object[] | object`

アシスタントメッセージのコンテンツ

**choices\[].message.images** `object[]`

画像生成モデルによって生成された画像

**choices\[].message.images\[].image\_url** `object` *required*

**choices\[].message.images\[].image\_url.url** `string` *required*

生成された画像の URL または base64 エンコードされたデータ

**choices\[].message.name** `string`

アシスタントのオプション名

**choices\[].message.reasoning** `string`

推論の出力

**choices\[].message.reasoning\_details** `object[]`

拡張思考モデルの推論の詳細

**choices\[].message.refusal** `string`

コンテンツが拒否された場合の拒否メッセージ

**choices\[].message.tool\_calls** `object[]`

アシスタントが実行したツール呼び出し

**choices\[].message.tool\_calls\[].function** `object` *required*

**choices\[].message.tool\_calls\[].function.arguments** `string` *required*

JSON 文字列としての関数の引数

**choices\[].message.tool\_calls\[].function.name** `string` *required*

呼び出す関数名

**choices\[].message.tool\_calls\[].id** `string` *required*

ツール呼び出しの識別子

**choices\[].message.tool\_calls\[].type** `string` *required*

指定可能な値: `function`

**created** `integer` *required*

作成時の Unix タイムスタンプ

**id** `string` *required*

一意の補完識別子

**model** `string` *required*

補完に使用されたモデル

**object** `string` *required*

指定可能な値: `chat.completion`

**openrouter\_metadata** `object`

**openrouter\_metadata.attempt** `integer` *required*

**openrouter\_metadata.attempts** `object[]`

**openrouter\_metadata.attempts\[].model** `string` *required*

**openrouter\_metadata.attempts\[].provider** `string` *required*

**openrouter\_metadata.attempts\[].status** `integer` *required*

**openrouter\_metadata.endpoints** `object` *required*

**openrouter\_metadata.endpoints.available** `object[]` *required*

**openrouter\_metadata.endpoints.available\[].model** `string` *required*

**openrouter\_metadata.endpoints.available\[].provider** `string` *required*

**openrouter\_metadata.endpoints.available\[].selected** `boolean` *required*

**openrouter\_metadata.endpoints.total** `integer` *required*

**openrouter\_metadata.is\_byok** `boolean` *required*

**openrouter\_metadata.params** `object`

**openrouter\_metadata.params.quality\_floor** `number`

フォーマット: `double`

**openrouter\_metadata.params.throughput\_floor** `number`

フォーマット: `double`

**openrouter\_metadata.params.version\_group** `string`

**openrouter\_metadata.pipeline** `object[]`

**openrouter\_metadata.pipeline\[].cost\_usd** `number`

フォーマット: `double`

**openrouter\_metadata.pipeline\[].data** `object`

**openrouter\_metadata.pipeline\[].guardrail\_id** `string`

**openrouter\_metadata.pipeline\[].guardrail\_scope** `string`

**openrouter\_metadata.pipeline\[].name** `string` *required*

**openrouter\_metadata.pipeline\[].summary** `string`

**openrouter\_metadata.pipeline\[].type** `string` *required*

パイプラインステージのカテゴリ種別。複数のプラグインが同じ type を共有できます（例: guardrail レベルのプラグインはすべて `guardrail` を出力します）。どのプラグインが出力したかは `name` フィールドで区別します。

指定可能な値: `guardrail`、`plugin`、`server_tools`、`response_healing`、`context_compression`

**openrouter\_metadata.region** `string` *required*

**openrouter\_metadata.requested** `string` *required*

**openrouter\_metadata.strategy** `string` *required*

指定可能な値: `direct`、`auto`、`free`、`latest`、`alias`、`fallback`、`pareto`、`bodybuilder`、`fusion`

**openrouter\_metadata.summary** `string` *required*

**service\_tier** `string`

このリクエストに対して上流のプロバイダーが使用したサービス階層

**system\_fingerprint** `string` *required*

システムフィンガープリント

**usage** `object`

トークン使用量の統計

**usage.completion\_tokens** `integer` *required*

補完（completion）のトークン数

**usage.completion\_tokens\_details** `object`

補完のトークン使用量の詳細

**usage.cost** `number`

補完のコスト

フォーマット: `double`

**usage.cost\_details** `object`

上流の推論コストの内訳

**usage.cost\_details.upstream\_inference\_completions\_cost** `number` *required*

フォーマット: `double`

**usage.cost\_details.upstream\_inference\_cost** `number`

フォーマット: `double`

**usage.cost\_details.upstream\_inference\_prompt\_cost** `number` *required*

フォーマット: `double`

**usage.is\_byok** `boolean`

リクエストが Bring Your Own Key 構成を使用して行われたかどうか

**usage.prompt\_tokens** `integer` *required*

プロンプトのトークン数

**usage.prompt\_tokens\_details** `object`

プロンプトのトークン使用量の詳細

**usage.total\_tokens** `integer` *required*

トークンの合計数

## 例

### 出力

```json theme={null}
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "ok"
      }
    }
  ],
  "created": 1750000000,
  "id": "gen-0000000000-examplecompletion",
  "model": "anthropic/claude-sonnet-4.5",
  "object": "chat.completion",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 128,
    "cost": 0.00123,
    "prompt_tokens": 42,
    "total_tokens": 170
  }
}
```

## 出荷前の確認

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

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

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

このページは、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](https://docs.comfy.org/ja/development/api-development/sdks.md) を参照してください。

> [card] [ヘッダー](https://docs.comfy.org/ja/development/comfy-router/headers.md)
>
> 認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。

> [card] [Router API の利用](https://docs.comfy.org/ja/development/comfy-router/api.md)
>
> モデルの検出、バリデーションエラー、リトライ、課金。

> [card] [制限事項](https://docs.comfy.org/ja/development/comfy-router/limitations.md)
>
> Router が現在対応していないことと、代替手段。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.