Add Comfy-Usage-Source pass-through for API node requests#14404
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new hidden input COMFY_USAGE_SOURCE (Hidden.comfy_usage_source / comfy_usage_source) accepted by HiddenHolder and registered for API nodes. The server copies an incoming Comfy-Usage-Source request header into extra_data when missing; execution reads that into hidden inputs (V3 and legacy). get_usage_source and get_comfy_api_headers expose the value (fallback "comfyui-api"), and client, Sonilo, and cloud-download code use get_comfy_api_headers so outbound requests include a Comfy-Usage-Source header. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Capture the Comfy-Usage-Source header (or extra_data.comfy_usage_source) on POST /prompt and forward it on API nodes' outbound requests to api.comfy.org, defaulting to comfyui-server when absent.
76977f4 to
d3878ed
Compare
|
I am concerned this could be redundant or create confusion with the
What do you think @robinjhuang ? |
So usage source is the surface that the user is initiating the call from. |
…-Org#12772) Adds `comfy_usage_source: 'comfyui-frontend'` to the prompt body's `extra_data`. The backend forwards this to API nodes' upstream requests via the `Comfy-Usage-Source` header, so partner node API usage can be attributed to the frontend. Used in Comfy-Org/ComfyUI#14404
The definition of environment (where it's installed) vs surface (from where it's used) make sense, but then we would need to adjust the values a bit:
I think it would make sense after adjusting the values:
|
|
Overall looks fine, only was able to find that Comfy-Env is not sent to everything + the manual requirement to add the header to sonilo. Adding a helper to make sure Comfy-Env + Comfy-Usage-Source will be accounted for universally would help, in case we add more headers in the future so we don't forget anything. |
|
Posted by an AI agent (Amp) on behalf of @Kosinkadink. Nice clean pass-through! One suggestion: the three outbound call sites that hit the Comfy API now build an overlapping header set by hand, and they've drifted — Consider factoring the common set into a single helper in def get_comfy_api_headers(node_cls: type[IO.ComfyNode]) -> dict[str, str]:
"""Common headers (auth, deploy environment, usage source) for Comfy API requests.
Centralizes these headers so every Comfy API request sends a consistent set and new
shared headers only need to be added in one place. Intended for relative/cloud URLs
resolved against ``default_base_url()``; because the result includes auth, callers must
not attach it to arbitrary absolute/presigned URLs.
"""
return {
**get_auth_header(node_cls),
"Comfy-Env": get_deploy_environment(),
"Comfy-Usage-Source": get_usage_source(node_cls),
}Then the call sites collapse to one line each: # client.py (relative URLs only)
payload_headers.update(get_comfy_api_headers(cfg.node_cls))
# nodes_sonilo.py
headers = get_comfy_api_headers(cls)
headers.update(endpoint.headers)
# download_helpers.py (relative 'cloud' URLs only)
headers = get_comfy_api_headers(cls)Note this also adds |
Yes! Comfy-Usage-Source: comfyui-server is for direct api calls. Updated to send as |
|
@Kosinkadink Done in b58af42 — shared headers (auth, Comfy-Env, Comfy-Usage-Source) are now centralized in |
|
nice, lgtm |
|
@alexisrolland any further comments on this? |
…nto add-comfy-usage-source-header
Captures the
Comfy-Usage-Sourceheader (orextra_data.comfy_usage_source) onPOST /promptand forwards it on API nodes' requests to api.comfy.org, defaulting tocomfyui-apifor direct API calls that don't identify themselves. Lets partner node API usage be attributed to the originating client. Shared outbound headers (auth,Comfy-Env,Comfy-Usage-Source) are centralized in aget_comfy_api_headers()helper — note this also addsComfy-Envto the Sonilo streaming and relative download paths, which previously only sent auth.API Node PR Checklist
Scope
Pricing & Billing
If Need pricing update:
QA
Comms