From 35655b9bf6e774783524457e301ac51a9a55cdac Mon Sep 17 00:00:00 2001 From: RITIK Date: Wed, 26 Nov 2025 15:00:30 +0530 Subject: [PATCH] Make base URL configurable and move to config --- README.md | 2 ++ config.ini | 1 + nodes/flux2_config.py | 18 ++++++++++++++++++ nodes/flux2_utils.py | 8 ++++---- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1469d46..4c1a9c2 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,11 @@ Repo layout (mirrors Floyo Seed API style): ```ini [API] BFL_API_KEY = + BFL_BASE_URL = https://api.bfl.ai/v1/flux-2-pro ``` ```bash export BFL_API_KEY= + export BFL_BASE_URL=https://api.bfl.ai/v1/flux-2-pro ``` 4. Restart ComfyUI. diff --git a/config.ini b/config.ini index 8b685ea..142f370 100644 --- a/config.ini +++ b/config.ini @@ -1,2 +1,3 @@ [API] BFL_API_KEY = +BFL_BASE_URL = https://api.bfl.ai/v1/flux-2-pro diff --git a/nodes/flux2_config.py b/nodes/flux2_config.py index 6bf443d..675bedd 100644 --- a/nodes/flux2_config.py +++ b/nodes/flux2_config.py @@ -23,6 +23,8 @@ class Flux2Config: key_from_env = os.environ.get("BFL_API_KEY") key_from_file = config.get("API", "BFL_API_KEY", fallback=None) + base_from_env = os.environ.get("BFL_BASE_URL") + base_from_file = config.get("API", "BFL_BASE_URL", fallback=None) if key_from_env: self._key = key_from_env @@ -35,9 +37,25 @@ class Flux2Config: self._key = None print("WARNING: No BFL_API_KEY found. Please set it in config.ini or as an environment variable.") + default_base = "https://api.bfl.ai/v1/flux-2-pro" + if base_from_env: + self._base_url = base_from_env + print(f"BFL_BASE_URL loaded from environment: {self._base_url}") + elif base_from_file: + self._base_url = base_from_file + os.environ.setdefault("BFL_BASE_URL", self._base_url) + print(f"BFL_BASE_URL loaded from config.ini: {self._base_url}") + else: + self._base_url = default_base + print(f"BFL_BASE_URL not set; using default {default_base}") + if self._key and self._key.strip() == "": print("WARNING: BFL_API_KEY is still the placeholder value. Replace it with a real key from https://api.bfl.ai.") def get_key(self): """Return the configured API key or None when missing.""" return self._key + + def get_base_url(self): + """Return the configured base URL for FLUX.2 API.""" + return self._base_url diff --git a/nodes/flux2_utils.py b/nodes/flux2_utils.py index 28ef75d..b964253 100644 --- a/nodes/flux2_utils.py +++ b/nodes/flux2_utils.py @@ -18,17 +18,17 @@ class Flux2APIError(Exception): class Flux2API: """Minimal client for the Black Forest Labs FLUX.2 [pro] endpoint.""" - BASE_URL = "https://api.bfl.ai/v1/flux-2-pro" - def __init__(self, timeout: int = 600, poll_interval: float = 1.0): self.timeout = timeout self.poll_interval = poll_interval - api_key = Flux2Config().get_key() + cfg = Flux2Config() + api_key = cfg.get_key() if not api_key: raise Flux2APIError( "BFL_API_KEY is not set. Define it in config.ini or export BFL_API_KEY before running ComfyUI." ) + self.base_url = cfg.get_base_url() self.headers = { "accept": "application/json", @@ -51,7 +51,7 @@ class Flux2API: def submit_request(self, payload: Dict[str, Any]) -> Dict[str, Any]: """Submit a generation/editing request and return the raw API response.""" body = self._strip_empty(payload) - response = requests.post(self.BASE_URL, headers=self.headers, json=body, timeout=30) + response = requests.post(self.base_url, headers=self.headers, json=body, timeout=30) response.raise_for_status() data = response.json()