Skip to content

feat!: configure the base URL via COMFY_BASE_URL instead of a constructor argument - #43

Merged
wei-hai merged 4 commits into
mainfrom
wei/be-6958-sdk-base-url-env-var
Aug 11, 2026
Merged

feat!: configure the base URL via COMFY_BASE_URL instead of a constructor argument#43
wei-hai merged 4 commits into
mainfrom
wei/be-6958-sdk-base-url-env-var

Conversation

@wei-hai

@wei-hai wei-hai commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Comfy() / AsyncComfy() target Comfy Cloud; another deployment is selected with the COMFY_BASE_URL environment variable. The base-URL constructor parameter is removed, so an arbitrary endpoint is no longer part of the call surface.

Breaking: Comfy(base_url, api_key)Comfy(api_key=...) + COMFY_BASE_URL. api_key is keyword-only now, so the old positional form raises TypeError instead of quietly reading a URL as a key.

The variable is read per construction (not at import), must be an http(s) URL, and unset-or-blank means Comfy Cloud.

Test suite: the server fixture points the SDK at the stub by setting the variable, so tests construct a bare Comfy(); an autouse fixture scrubs an ambient value so a developer's own shell can't aim the suite at a real deployment. That is most of the diff.

Scope: the public clients only. comfy_low (the documented escape hatch) still takes a base URL — it is what the clients build on.

Verified: ruff check, ruff format --check, mypy src, pytest (120 pass, 4 skipped).

Matching change in comfy-typescript-sdk keeps the two SDKs in lockstep.

Summary by CodeRabbit

  • New Features

    • Clients now use Comfy Cloud by default.
    • Select a self-hosted deployment with the COMFY_BASE_URL environment variable.
    • Base URL configuration is validated to accept only HTTP(S) addresses.
    • The base URL environment variable is publicly available for configuration.
    • API keys are provided as keyword arguments for synchronous and asynchronous clients.
  • Documentation

    • Updated setup, deployment, authentication, and async usage examples.
    • Clarified API-key requirements and cross-origin request restrictions.

…rgument

`Comfy`/`AsyncComfy` now always target Comfy Cloud unless the
`COMFY_BASE_URL` environment variable names another deployment. The
base-URL constructor parameter is gone, so an arbitrary endpoint is no
longer part of the call surface.

`api_key` is keyword-only now: the old positional `Comfy(url, key)` form
would otherwise read a URL as a key silently.

The variable is read per construction (not at import), must be an
http(s) URL, and unset-or-blank means Comfy Cloud. The unit suite's
`server` fixture sets it, so tests construct a bare `Comfy()`, and an
autouse fixture scrubs an ambient value so a developer's own shell
cannot point the suite at a real deployment.
@wei-hai
wei-hai requested review from a team as code owners August 11, 2026 19:47
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@wei-hai, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0b7aea4e-274f-4292-af6b-23c8060f11bb

📥 Commits

Reviewing files that changed from the base of the PR and between 95bd1ff and 3a8f21e.

📒 Files selected for processing (5)
  • README.md
  • src/comfy_sdk/client.py
  • tests/conftest.py
  • tests/integration/test_gateway_e2e.py
  • tests/test_base_url_env.py
📝 Walkthrough

Walkthrough

The SDK now selects deployment targets through COMFY_BASE_URL, defaults to Comfy Cloud, validates overrides, and removes positional base-URL constructor arguments. Public exports, documentation, test fixtures, and client usage tests reflect this configuration model.

Changes

Deployment targeting

Layer / File(s) Summary
Client URL resolution and constructor API
src/comfy_sdk/client.py, src/comfy_sdk/__init__.py
Comfy and AsyncComfy resolve and validate COMFY_BASE_URL at construction. Blank values use Comfy Cloud. BASE_URL_ENV_VAR is publicly exported.
Environment isolation and configuration validation
tests/conftest.py, tests/test_base_url_env.py, tests/integration/test_gateway_e2e.py
Test fixtures configure the stub server through the exported environment-variable constant. Tests cover defaults, overrides, normalization, validation, construction-time lookup, and positional-argument rejection.
Client usage migration and behavior validation
tests/test_assets.py, tests/test_async.py, tests/test_auth_headers.py, tests/test_content_redirect_security.py, tests/test_download_and_workflows.py, tests/test_events.py, tests/test_get_download_url.py, tests/test_jobs.py, tests/test_sse_idle.py, tests/test_user_agent.py
Existing tests construct clients through environment configuration while retaining coverage for authentication, downloads, events, uploads, jobs, streaming, redirects, and user-agent behavior.
Deployment and authentication documentation
README.md
The README documents deployment selection, keyword-based API-key construction, authentication requirements, origin restrictions, and Cloud-default examples.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant Comfy
  participant Environment
  participant ComfyLow
  Application->>Comfy: construct client
  Comfy->>Environment: read COMFY_BASE_URL
  Environment-->>Comfy: configured URL or blank value
  Comfy->>Comfy: validate URL or select Comfy Cloud
  Comfy->>ComfyLow: initialize resolved deployment client
Loading

Suggested reviewers: alexisrolland

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the breaking change from constructor-based base URL configuration to COMFY_BASE_URL.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wei/be-6958-sdk-base-url-env-var

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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: 4

🤖 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 `@README.md`:
- Around line 76-90: Add a migration note near the Comfy/AsyncComfy constructor
examples explicitly stating that api_key must now be passed by keyword, the
former positional base-URL constructor is unsupported, and COMFY_BASE_URL must
be configured before constructing either client.

In `@src/comfy_sdk/client.py`:
- Around line 58-63: Update _resolve_base_url to access parsed.port after
validating the URL components, causing malformed or out-of-range ports to raise
the existing COMFY_BASE_URL ValueError before returning the URL to ComfyLow.

In `@tests/integration/test_gateway_e2e.py`:
- Around line 96-102: Update the client fixture function client to accept the
pytest monkeypatch fixture and replace the direct os.environ assignment with
monkeypatch.setenv(BASE_URL_ENV_VAR, BASE_URL), ensuring COMFY_BASE_URL is
automatically restored after the fixture while preserving the existing client
setup and cleanup.

In `@tests/test_base_url_env.py`:
- Around line 80-93: Add asynchronous tests alongside
test_async_env_var_selects_the_deployment covering blank and whitespace-only
COMFY_BASE_URL values, whitespace trimming, and malformed URL rejection,
mirroring the synchronous cases from lines 45-71. Exercise AsyncComfy’s actual
URL resolution and validation behavior, asserting defaults or normalized URLs
where appropriate and the expected exception for malformed values.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5f3b6669-93c5-4acc-962f-452fe6d7c514

📥 Commits

Reviewing files that changed from the base of the PR and between cd90a51 and 95bd1ff.

📒 Files selected for processing (17)
  • README.md
  • src/comfy_sdk/__init__.py
  • src/comfy_sdk/client.py
  • tests/conftest.py
  • tests/integration/test_gateway_e2e.py
  • tests/test_assets.py
  • tests/test_async.py
  • tests/test_auth_headers.py
  • tests/test_base_url_env.py
  • tests/test_content_redirect_security.py
  • tests/test_default_base_url.py
  • tests/test_download_and_workflows.py
  • tests/test_events.py
  • tests/test_get_download_url.py
  • tests/test_jobs.py
  • tests/test_sse_idle.py
  • tests/test_user_agent.py
💤 Files with no reviewable changes (1)
  • tests/test_default_base_url.py

Comment thread README.md
Comment thread src/comfy_sdk/client.py
Comment thread tests/integration/test_gateway_e2e.py
Comment thread tests/test_base_url_env.py
urlsplit defers the port check, so `http://host:bad` passed validation
and only failed later inside httpx. Reading `.port` in the resolver
turns it into the same clear COMFY_BASE_URL error.

README: blank means whitespace-only too, plus a migration line for the
keyword-only `api_key`.
The transport builds request URLs by appending the API path to this
string, so `https://host?x=1` put `/api/v2/...` inside the query and the
request never reached the endpoint. Also cover AsyncComfy in the
malformed-value tests.
The e2e fixture set COMFY_BASE_URL directly and never unset it. Scope
the unit-suite scrub to skip tests/integration instead, so that suite
simply inherits the variable it is configured with and monkeypatch
leaves the environment as it was found.

Also fixes the latent trap that the variable was absent during the
module's later tests, so a client built inside a test body would have
targeted Comfy Cloud.
@wei-hai

wei-hai commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

All four findings are addressed (replies on each thread): the migration note, port validation, the async rejection test, and the gateway fixture no longer mutating os.environ. Also picked up the query/fragment guard from the TypeScript review, since this transport concatenates the same way.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

@wei-hai: I will verify the four fixes and the query/fragment validation change.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@wei-hai
wei-hai merged commit cd8193a into main Aug 11, 2026
11 checks passed
@wei-hai
wei-hai deleted the wei/be-6958-sdk-base-url-env-var branch August 11, 2026 23:15
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants