使用 Comfy Router 处理图像
通过 Comfy Router 调用 openrouter/images:端点、请求结构以及 Router 返回的响应。
使用 Comfy Router 处理图像
通过 Comfy Router 调用 openrouter/images:端点、请求结构以及 Router 返回的响应。
openrouter/images 的 API 参考,由 Comfy Router 从 Openrouter 提供。
输入: 文本、图像 · 输出: 图像
请求设置
在你的 Comfy 工作区中创建一个密钥,并将其导出为 COMFY_API_KEY。对于 Python,运行 pip install comfy-sdk。对于 TypeScript,运行 npm install @comfyorg/sdk。cURL 使用原始 HTTP。
模型 ID: openrouter/images
端点: POST https://api.comfy.org/v2/models/openrouter/images
注意 此模型没有可运行的请求示例。请根据下方的输入文档构建请求体,然后将其与 Router 快速入门配合使用。
Schema
输入
aspect\_ratio string
输出宽高比
background string
背景模式
input\_references object[]
用于图生图生成的参考图像,以 data URL 或 HTTP(S) URL 形式提供
input\_references\[].image\_url object required
input\_references\[].image\_url.detail string
视觉模型的图像细节级别
可能的值:auto、low、high
input\_references\[].image\_url.url string required
图像 URL(支持 data: URL)
input\_references\[].type string required
内容部分类型,始终为 image\_url
model string
要使用的图像生成模型,采用 OpenRouter 模型 ID,例如 microsoft/mai-image-2.6 或 microsoft/mai-image-2.6-flash。
n integer
要生成的图像数量
output\_compression integer
webp/jpeg 输出的压缩级别
output\_format string
输出图像格式
prompt string required
期望图像的文本描述
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[]
要忽略的提供商 slug 列表。若提供,此列表会与你账户范围内针对此请求忽略的提供商设置合并。
provider.max\_price object
用于指定你愿意为此请求支付的最高价格的对象。以美元计价的每百万 token 价格,适用于提示词和补全。
provider.max\_price.audio string
每百万提示 token 的价格
provider.max\_price.completion string
每百万提示 token 的价格
provider.max\_price.image string
每百万提示 token 的价格
provider.max\_price.prompt string
每百万提示 token 的价格
provider.max\_price.request string
每百万提示 token 的价格
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[]
要允许的提供商 slug 列表。若提供,此列表会与你账户范围内针对此请求允许的提供商设置合并。
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[]
按顺序排列的提供商 slug 列表。路由器会尝试使用此列表子集中第一个支持你所请求模型的提供商,如果该提供商不可用,则回退到下一个。如果没有任何提供商可用,请求将失败并返回报错信息。
provider.preferred\_max\_latency number | object
首选最大延迟(以秒为单位)。可以是数字(应用于 p50),也可以是包含按百分位设置的截止值的对象。高于阈值的端点仍可能被使用,但在路由中的优先级会降低。使用回退模型时,如果回退模型满足阈值,这可能导致改用回退模型而不是主模型。
provider.preferred\_min\_throughput number | object
首选最小吞吐量(以每秒 token 数为单位)。可以是数字(应用于 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(零数据保留)端点。当为 true 时,只会使用不保留提示词的端点。
quality string
输出质量预设
resolution string
输出分辨率预设
seed integer
用于确定性生成的种子
size string
输出图像尺寸
stream boolean
为部分图像启用 SSE 流式传输。/proxy/ 路由会以 400 拒绝 stream: true。Comfy Router 会将其设为 false 并处理请求。
user string
稳定的最终用户标识符
根据 Router 在 GET /v2/models/openrouter/images/openapi.json 提供的 schema 生成,该文档也是它在请求到达提供商之前用于校验调用的同一份文档。### 输出
输出
created integer
创建时间的 Unix 时间戳
data object[]
已生成的图像
data\[].b64\_json string
Base64 编码的图像数据。当响应大于 1,048,576 字节时,Comfy Router 会用 url 取而代之。当响应不大于该值时,或图像上传到 Comfy 存储失败时,图像仍保留在此字段中。
data\[].media\_type string
图像的 MIME 类型
data\[].url string
由 Comfy 托管的图像签名 URL,当响应大于 1,048,576 字节时以其替代 b64_json 返回。Comfy Router 始终会请求它;/proxy/ 路由仅在请求发送 Comfy-Asset-Format: url 时才会请求它。零数据保留工作区永远不会获得它:其图像仍保留在 b64_json 中。该 URL 在调用后 24 小时过期。
usage object
图像生成用量
usage.completion\_tokens integer
生成的 token 数
usage.cost number
请求的总 USD 费用
格式:double
usage.prompt\_tokens integer
用于输入的 token 数
usage.total\_tokens integer
请求的总 token 数
示例
输出
{
"created": 1767225600,
"data": [
{
"media_type": "image/png",
"url": "https://storage.googleapis.com/example-bucket/openrouter-images/example.png"
}
],
"usage": {
"completion_tokens": 1024,
"cost": 0.03,
"prompt_tokens": 12,
"total_tokens": 1036
}
}
发布前须知
SDK 会生成 Idempotency-Key 并在自动重试中复用它。手动重试时,请复用原始 key。Router 最长可保持连接 10 分钟。
请求失败时,Router 会发送 X-Comfy-Error-Type 响应头说明原因。422 表示 Router 在调用提供商之前就拒绝了输入,413 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载,因为结果 URL 会过期。
上文任何字段描述中提到的尺寸限制,都是提供商对该字段自身的限定,引自提供商的规范。Router 会对整个请求体另行设置上限,base64 编码的媒体内容也计入其中:参见请求体大小。
本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 comfy-sdk / @comfyorg/sdk 包还提供第二个客户端,用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图:Comfy(api_key=...) / new Comfy({ apiKey }),并带有 client.workflows、client.assets 和 client.jobs。请参阅 Comfy SDKs。
请求头 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
使用 Router API 模型发现、验证错误、重试与计费。
限制 Router 目前不支持的功能,以及替代方案。