From f14b55f0d773e910512f395fa8645a78e58886d5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 5 Apr 2026 09:01:28 +0000 Subject: [PATCH] fix(grok): sanitize user-provided xAI API key - Strips leading/trailing whitespace - Removes accidental `Bearer ` prefixes from pasted keys This prevents xAI API rejection errors such as "Incorrect API key provided" when the key format is slightly off. Co-authored-by: austin1997 <18709560+austin1997@users.noreply.github.com> --- comfy_api_nodes/nodes_grok.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/comfy_api_nodes/nodes_grok.py b/comfy_api_nodes/nodes_grok.py index 3f0d82977..fdf19fecd 100644 --- a/comfy_api_nodes/nodes_grok.py +++ b/comfy_api_nodes/nodes_grok.py @@ -141,6 +141,10 @@ class GrokImageNode(IO.ComfyNode): ) -> IO.NodeOutput: validate_string(prompt, strip_whitespace=True, min_length=1) + xai_api_key = xai_api_key.strip() + if xai_api_key.lower().startswith("bearer "): + xai_api_key = xai_api_key[7:].strip() + path = "/proxy/xai/v1/images/generations" headers = None if xai_api_key: @@ -283,6 +287,10 @@ class GrokImageEditNode(IO.ComfyNode): "Custom aspect ratio is only allowed when multiple images are connected to the image input." ) + xai_api_key = xai_api_key.strip() + if xai_api_key.lower().startswith("bearer "): + xai_api_key = xai_api_key[7:].strip() + path = "/proxy/xai/v1/images/edits" headers = None if xai_api_key: @@ -410,6 +418,10 @@ class GrokVideoNode(IO.ComfyNode): image_url = InputUrlObject(url=f"data:image/png;base64,{tensor_to_base64_string(image)}") validate_string(prompt, strip_whitespace=True, min_length=1) + xai_api_key = xai_api_key.strip() + if xai_api_key.lower().startswith("bearer "): + xai_api_key = xai_api_key[7:].strip() + path = "/proxy/xai/v1/videos/generations" headers = None if xai_api_key: @@ -510,6 +522,10 @@ class GrokVideoEditNode(IO.ComfyNode): if video_size > 50 * 1024 * 1024: raise ValueError(f"Video size ({video_size / 1024 / 1024:.1f}MB) exceeds 50MB limit.") + xai_api_key = xai_api_key.strip() + if xai_api_key.lower().startswith("bearer "): + xai_api_key = xai_api_key[7:].strip() + path = "/proxy/xai/v1/videos/edits" headers = None if xai_api_key: @@ -652,6 +668,10 @@ class GrokVideoReferenceNode(IO.ComfyNode): ) -> IO.NodeOutput: validate_string(prompt, strip_whitespace=True, min_length=1) + xai_api_key = xai_api_key.strip() + if xai_api_key.lower().startswith("bearer "): + xai_api_key = xai_api_key[7:].strip() + # We must use proxy to upload images temporarily even if they provide their own key for video generation # because the API requires URLs and we use our proxy for image hosting during the request. # Wait, if they are providing their own key to our backend for generation, @@ -792,6 +812,10 @@ class GrokVideoExtendNode(IO.ComfyNode): if video_size > 50 * 1024 * 1024: raise ValueError(f"Video size ({video_size / 1024 / 1024:.1f}MB) exceeds 50MB limit.") + xai_api_key = xai_api_key.strip() + if xai_api_key.lower().startswith("bearer "): + xai_api_key = xai_api_key[7:].strip() + path = "/proxy/xai/v1/videos/extensions" headers = None if xai_api_key: