diff --git a/modules/mediaUpload.py b/modules/mediaUpload.py index 1b4f691..ffa6fef 100644 --- a/modules/mediaUpload.py +++ b/modules/mediaUpload.py @@ -7,10 +7,10 @@ import soundfile as sf import numpy as np from io import BytesIO from .utils.runwareUtils import ( - RUNWARE_API_KEY, RUNWARE_API_BASE_URL, generalRequestWrapper, genRandUUID, + getRunwareApiHeaders, sanitize_for_logging, safe_json_dumps, sendMediaUUID, @@ -237,21 +237,13 @@ class RunwareMediaUpload: "media": mediaData, }] - def _getApiHeaders(self): - """Get API request headers""" - return { - "Authorization": f"Bearer {RUNWARE_API_KEY}", - "Content-Type": "application/json", - "Accept-Encoding": "gzip, deflate, br, zstd", - } - def _makeUploadRequest(self, uploadConfig): """Make upload request to Runware API""" def recaller(): print(f"[Debug] Making POST request to Runware API...") return requests.post( RUNWARE_API_BASE_URL, - headers=self._getApiHeaders(), + headers=getRunwareApiHeaders(), json=uploadConfig, timeout=self.REQUEST_TIMEOUT, allow_redirects=False, @@ -301,7 +293,7 @@ class RunwareMediaUpload: def recaller(): return requests.post( RUNWARE_API_BASE_URL, - headers=self._getApiHeaders(), + headers=getRunwareApiHeaders(), json=pollConfig, timeout=self.REQUEST_TIMEOUT, allow_redirects=False, diff --git a/modules/utils/runwareUtils.py b/modules/utils/runwareUtils.py index 0c97b0f..ffaed21 100644 --- a/modules/utils/runwareUtils.py +++ b/modules/utils/runwareUtils.py @@ -22,6 +22,20 @@ import re load_dotenv() +from ...version import __version__ + +def getRunwareApiHeaders(include_auth=True): + headers = { + "Content-Type": "application/json", + "Accept": "application/json", + "Accept-Encoding": "gzip, deflate, br, zstd", + "X-SDK-Name": "comfyui", + "X-SDK-Version": __version__, + } + if include_auth: + headers["Authorization"] = f"Bearer {os.getenv('RUNWARE_API_KEY')}" + return headers + BASEFOLDER = Path(__file__).parent.parent.parent IMAGE_CACHE_FILE = BASEFOLDER / "imagesCache.json" @@ -250,12 +264,7 @@ def getOrdinal(num): return ordinals.get(num, f"{num}th") def checkAPIKey(apiKey): - headers = { - "Accept": "application/json", - "Content-Type": "application/json", - "Accept-Encoding": "gzip, deflate, br, zstd", - } - + headers = getRunwareApiHeaders(include_auth=False) genConfig = [ { "taskType": "authentication", @@ -359,11 +368,7 @@ def inferenecRequest(genConfig): global RUNWARE_API_KEY, RUNWARE_API_BASE_URL, SESSION_TIMEOUT RUNWARE_API_KEY = os.getenv("RUNWARE_API_KEY") SESSION_TIMEOUT = int(os.getenv("RUNWARE_TIMEOUT")) - headers = { - "Authorization": f"Bearer {RUNWARE_API_KEY}", - "Content-Type": "application/json", - "Accept-Encoding": "gzip, deflate, br, zstd", - } + headers = getRunwareApiHeaders() try: def recaller(): @@ -720,11 +725,7 @@ def pollVideoResult(taskUUID): } ] - headers = { - "Authorization": f"Bearer {RUNWARE_API_KEY}", - "Content-Type": "application/json", - "Accept-Encoding": "gzip, deflate, br, zstd", - } + headers = getRunwareApiHeaders() try: def recaller(): diff --git a/version.py b/version.py new file mode 100644 index 0000000..17ecd62 --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +__version__ = "1.8.6"