Skip to content

Add Comfy-Usage-Source header to ComfyUI and cloud API requests#468

Merged
bigcat88 merged 2 commits into
mainfrom
add-comfy-usage-source-header
Jun 11, 2026
Merged

Add Comfy-Usage-Source header to ComfyUI and cloud API requests#468
bigcat88 merged 2 commits into
mainfrom
add-comfy-usage-source-header

Conversation

@robinjhuang

@robinjhuang robinjhuang commented Jun 10, 2026

Copy link
Copy Markdown
Member

Adds a Comfy-Usage-Source: comfy-cli header (and extra_data.comfy_usage_source) when submitting workflows to a ComfyUI server, and the same header on cloud generate API requests. Allows partner node API usage to be attributed to the CLI.

Used in Comfy-Org/ComfyUI#14404

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. enhancement New feature or request labels Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds CLI-identifying metadata and headers: _auth_headers() now emits Comfy-Usage-Source: comfy-cli; WorkflowExecution.queue() always sets extra_data.comfy_usage_source = "comfy-cli", conditionally adds api_key_comfy_org, and sends a Comfy-Usage-Source header. Tests and the pytest CI workflow pin are updated.

Changes

Client identification across request paths

Layer / File(s) Summary
API auth header client identification
comfy_cli/command/generate/client.py
_auth_headers adds Comfy-Usage-Source: comfy-cli to the default headers alongside User-Agent and Comfy-Env.
Workflow prompt metadata and headers
comfy_cli/command/run.py, tests/comfy_cli/command/test_run.py
WorkflowExecution.queue() sets extra_data.comfy_usage_source = "comfy-cli" unconditionally, adds extra_data.api_key_comfy_org when self.api_key is present, and includes a Comfy-Usage-Source: comfy-cli header on the /prompt request. Tests verify keyed and keyless behaviors.

CI workflow pin update

Layer / File(s) Summary
Codecov action pin
.github/workflows/pytest.yml
Updated the pinned codecov/codecov-action commit used by the Codecov upload step (v6.0.0 → v6.0.2).

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-comfy-usage-source-header
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch add-comfy-usage-source-header

Comment @coderabbitai help to get the list of available commands and usage tips.

@robinjhuang robinjhuang force-pushed the add-comfy-usage-source-header branch from 3fbae5b to ff2d9e7 Compare June 10, 2026 21:24
@robinjhuang robinjhuang requested a review from bigcat88 June 10, 2026 22:30
Codecov bricked their old keybase account; action versions before
v6.0.2 fail signature verification of the uploader (codecov-action#1956).
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@           Coverage Diff           @@
##             main     #468   +/-   ##
=======================================
  Coverage   83.25%   83.25%           
=======================================
  Files          45       45           
  Lines        6802     6804    +2     
=======================================
+ Hits         5663     5665    +2     
  Misses       1139     1139           
Files with missing lines Coverage Δ
comfy_cli/command/generate/client.py 78.26% <100.00%> (ø)
comfy_cli/command/run.py 90.99% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/pytest.yml:
- Line 41: The pinned SHA in the workflow uses line
(codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f) does not match
the inline comment label "# v6.0.2"; either update the uses value to the actual
commit SHA for tag v6.0.2 (replace fb8b... with
8cad3ba95e5920c42f44492e54bc9639cba47959) or change the inline comment to
reflect the true SHA you intend to pin (or simply use the tag form
codecov/codecov-action@v6.0.2 if you want the tag instead); edit the line that
contains codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f and the
adjacent comment to make them consistent.

In `@tests/comfy_cli/command/test_run.py`:
- Around line 201-207: The test test_queue_sends_usage_source_header is
asserting the wrong header casing; update the assertion to match the exact
header name used in run.py ("Comfy-Usage-Source") so it reads assert
req.get_header("Comfy-Usage-Source") == "comfy-cli" (or alternatively fetch
headers case-insensitively from req.header_items()), targeting the test function
test_queue_sends_usage_source_header and the code that calls
ex.queue()/urllib.request.Request to ensure casing matches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9a7ff5f2-dfc6-4674-aa75-8c0aad737f94

📥 Commits

Reviewing files that changed from the base of the PR and between 3fbae5b and 9a68f18.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • .github/workflows/pytest.yml
  • comfy_cli/command/generate/client.py
  • comfy_cli/command/run.py
  • tests/comfy_cli/command/test_run.py

Comment thread .github/workflows/pytest.yml
Comment on lines +201 to +207
def test_queue_sends_usage_source_header(self, workflow):
ex = self._make_exec(workflow)
with patch("comfy_cli.command.run.request.urlopen") as mock_open:
mock_open.return_value.read.return_value = json.dumps({"prompt_id": "abc"}).encode()
ex.queue()
req = mock_open.call_args[0][0]
assert req.get_header("Comfy-usage-source") == "comfy-cli"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify that urllib.request.Request.get_header() is case-insensitive

python -c "
import urllib.request

req = urllib.request.Request('http://example.com')
req.add_header('Comfy-Usage-Source', 'test-value')

# Test various casings
print('Exact match:', req.get_header('Comfy-Usage-Source'))
print('Lowercase u:', req.get_header('Comfy-usage-source'))
print('All lowercase:', req.get_header('comfy-usage-source'))
print('All uppercase:', req.get_header('COMFY-USAGE-SOURCE'))

# Check if all variants return the same value
variants = [
    req.get_header('Comfy-Usage-Source'),
    req.get_header('Comfy-usage-source'),
    req.get_header('comfy-usage-source'),
    req.get_header('COMFY-USAGE-SOURCE')
]
if all(v == 'test-value' for v in variants):
    print('✓ get_header() is case-insensitive')
else:
    print('✗ get_header() is case-sensitive - test may fail')
"

Repository: Comfy-Org/comfy-cli

Length of output: 194


Align Comfy-* header casing in the test.

run.py sets "Comfy-Usage-Source", but the test asserts req.get_header("Comfy-usage-source"); urllib.request.Request.get_header() can require matching header-name casing (returns None otherwise), so this assertion is brittle. Update the test to use the exact same header name casing—case closed! 🎭

🧰 Tools
🪛 Pylint (4.0.5)

[convention] 201-201: Missing function or method docstring

(C0116)


[warning] 201-201: Redefining name 'workflow' from outer scope (line 21)

(W0621)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/comfy_cli/command/test_run.py` around lines 201 - 207, The test
test_queue_sends_usage_source_header is asserting the wrong header casing;
update the assertion to match the exact header name used in run.py
("Comfy-Usage-Source") so it reads assert req.get_header("Comfy-Usage-Source")
== "comfy-cli" (or alternatively fetch headers case-insensitively from
req.header_items()), targeting the test function
test_queue_sends_usage_source_header and the code that calls
ex.queue()/urllib.request.Request to ensure casing matches.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 11, 2026
@bigcat88 bigcat88 merged commit a392f55 into main Jun 11, 2026
15 checks passed
@bigcat88 bigcat88 deleted the add-comfy-usage-source-header branch June 11, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants