Make base URL configurable and move to config
This commit is contained in:
@@ -26,9 +26,11 @@ Repo layout (mirrors Floyo Seed API style):
|
||||
```ini
|
||||
[API]
|
||||
BFL_API_KEY = <your_real_key>
|
||||
BFL_BASE_URL = https://api.bfl.ai/v1/flux-2-pro
|
||||
```
|
||||
```bash
|
||||
export BFL_API_KEY=<your_real_key>
|
||||
export BFL_BASE_URL=https://api.bfl.ai/v1/flux-2-pro
|
||||
```
|
||||
4. Restart ComfyUI.
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
[API]
|
||||
BFL_API_KEY = <your_bfl_api_key_here>
|
||||
BFL_BASE_URL = https://api.bfl.ai/v1/flux-2-pro
|
||||
|
||||
@@ -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() == "<your_bfl_api_key_here>":
|
||||
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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user