Skip to content

feat: Support xAI API key for Grok nodes#13294

Open
austin1997 wants to merge 5 commits intoComfy-Org:masterfrom
austin1997:master
Open

feat: Support xAI API key for Grok nodes#13294
austin1997 wants to merge 5 commits intoComfy-Org:masterfrom
austin1997:master

Conversation

@austin1997
Copy link
Copy Markdown

@austin1997 austin1997 commented Apr 5, 2026

Add optional xAI API key for Grok API nodes. Allowing users to provide existing xAI API keys.

API Node PR Checklist

Scope

  • [✅] Is API Node Change

Pricing & Billing

  • [❌] Need pricing update
  • [✅] No pricing update

If Need pricing update:

  • Metronome rate cards updated
  • Auto‑billing tests updated and passing

QA

  • QA done
  • QA not required

Comms

  • Informed Kosinkadink

google-labs-jules bot and others added 5 commits April 5, 2026 02:52
This adds an optional `xai_api_key` input to all Grok image and video nodes.
When provided, requests bypass the Comfy proxy and directly call the
official xAI endpoints, allowing users to use their own keys and bypass
Comfy org limits.

Co-authored-by: austin1997 <18709560+austin1997@users.noreply.github.com>
- 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>
- 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>
…4855872412057

feat: add official xAI API key support to Grok nodes
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

The PR adds an optional xai_api_key parameter to multiple Grok nodes: GrokImageNode, GrokImageEditNode, GrokVideoNode, GrokVideoEditNode, GrokVideoReferenceNode, and GrokVideoExtendNode. The parameter enables dynamic API endpoint routing—when provided, requests use direct https://api.x.ai/... endpoints with Bearer authentication; when absent, requests fall back to existing /proxy/xai/... paths. The key is sanitized (whitespace-trimmed and Bearer prefix removed) before use. Both initial operations and polling apply this conditional routing.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the addition of an optional xAI API key parameter to Grok nodes.
Title check ✅ Passed The title accurately summarizes the main change: adding support for xAI API key input to Grok nodes, which enables direct API calls and bypasses the Comfy proxy.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
comfy_api_nodes/nodes_grok.py (2)

675-678: Clean up developer deliberation comments.

These lines read like internal thought process rather than documentation. The first sentence is useful context, but the "Wait, if they are providing their own key..." part is confusing. Consider simplifying:

✏️ Suggested cleanup
-        # 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,
-        # `upload_images_to_comfyapi` relies on `comfyapi`. This is fine.
+        # Image uploads always use Comfy proxy for temporary hosting since the xAI API requires URLs.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@comfy_api_nodes/nodes_grok.py` around lines 675 - 678, Remove the internal
deliberation style comments around the image proxy explanation in nodes_grok.py
and replace them with a concise, clear comment: keep the first sentence that
explains we must use the proxy to upload images temporarily for API URL
requirements, remove the "Wait, if they are providing their own key..."
conversational lines, and optionally add a short clarifying note that
upload_images_to_comfyapi uses the comfyapi proxy for hosting during the
request; ensure the comment is factual and concise.

144-152: Consider extracting API key handling into a reusable helper.

This exact sanitization and path/header setup pattern is duplicated across all 6 Grok nodes. Extracting it would improve maintainability:

💡 Proposed helper function
def _prepare_xai_request(xai_api_key: str, proxy_path: str, direct_path: str) -> tuple[str, dict | None]:
    """Sanitize API key and return (path, headers) for xAI requests."""
    xai_api_key = xai_api_key.strip()
    if xai_api_key.lower().startswith("bearer "):
        xai_api_key = xai_api_key[7:].strip()
    
    if xai_api_key:
        return direct_path, {"Authorization": f"Bearer {xai_api_key}"}
    return proxy_path, None

Usage would become:

path, headers = _prepare_xai_request(
    xai_api_key,
    "/proxy/xai/v1/images/generations",
    "https://api.x.ai/v1/images/generations"
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@comfy_api_nodes/nodes_grok.py` around lines 144 - 152, Duplicate xAI API key
sanitization and path/header selection (the xai_api_key.strip(), bearer-prefix
removal, and setting path/headers) appears across all Grok nodes; factor it into
a reusable helper (e.g., _prepare_xai_request(xai_api_key: str, proxy_path: str,
direct_path: str) -> tuple[str, dict|None]) that performs the strip + "bearer "
removal and returns (path, headers). Replace the repeated block that sets path
and headers in each Grok node with a call to _prepare_xai_request(...), passing
the existing proxy path "/proxy/xai/v1/images/generations" and direct
"https://api.x.ai/v1/images/generations" (and analogous paths for other
endpoints), and ensure callers use the returned path and headers variables
(preserving current variable names xai_api_key handling is internal to the
helper).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@comfy_api_nodes/nodes_grok.py`:
- Around line 675-678: Remove the internal deliberation style comments around
the image proxy explanation in nodes_grok.py and replace them with a concise,
clear comment: keep the first sentence that explains we must use the proxy to
upload images temporarily for API URL requirements, remove the "Wait, if they
are providing their own key..." conversational lines, and optionally add a short
clarifying note that upload_images_to_comfyapi uses the comfyapi proxy for
hosting during the request; ensure the comment is factual and concise.
- Around line 144-152: Duplicate xAI API key sanitization and path/header
selection (the xai_api_key.strip(), bearer-prefix removal, and setting
path/headers) appears across all Grok nodes; factor it into a reusable helper
(e.g., _prepare_xai_request(xai_api_key: str, proxy_path: str, direct_path: str)
-> tuple[str, dict|None]) that performs the strip + "bearer " removal and
returns (path, headers). Replace the repeated block that sets path and headers
in each Grok node with a call to _prepare_xai_request(...), passing the existing
proxy path "/proxy/xai/v1/images/generations" and direct
"https://api.x.ai/v1/images/generations" (and analogous paths for other
endpoints), and ensure callers use the returned path and headers variables
(preserving current variable names xai_api_key handling is internal to the
helper).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0fb4e18c-152c-4f89-bf0c-076988655ac6

📥 Commits

Reviewing files that changed from the base of the PR and between 8cbbea8 and d2c287a.

📒 Files selected for processing (1)
  • comfy_api_nodes/nodes_grok.py

@austin1997 austin1997 changed the title Support xAI API key for Grok nodes feat: Support xAI API key for Grok nodes Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant