Comfy-Org / Comfy-Org/ComfyUI

Intermittent 401 "Invalid Comfy API key" from api.comfy.org , retrying 401 mitigates the issue

Open Beginner friendly
#15,856 0 comments 0 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 7h
Merged PRs (30d)
158

Description

### Custom Node Testing

- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

### Expected Behavior

A valid static Comfy API key should be accepted consistently by api.comfy.org.

Requests made from the same running ComfyUI instance with the same API key should not intermittently fail with HTTP 401 "Invalid Comfy API key".

If an authentication backend can transiently return a false 401, ComfyUI should retry the request instead of immediately failing the entire workflow.

### Actual Behavior

During longer workflows using Comfy API Nodes, api.comfy.org intermittently returns:

HTTP 401
{"message": "Invalid Comfy API key"}

The API key is static and remains valid. Requests immediately before and after the failing request succeed normally without logging in again, restarting ComfyUI, or changing the API key.

In one captured session I recorded:

- 781 completed HTTP responses
- 775x HTTP 200
- 6x HTTP 401
- all 6 returned "Invalid Comfy API key"

The issue occurred on multiple endpoints, including:

POST https://api.comfy.org/customers/storage

and

POST https://api.comfy.org/proxy/vertexai/gemini/gemini-3.1-pro-preview

ComfyUI currently treats the 401 as fatal and raises:

Unauthorized: Please login first to use this node.

As a temporary local hotfix, I added 401 to `_RETRY_STATUS` in `comfy_api_nodes/util/client.py`:

_RETRY_STATUS = {401, 408, 500, 502, 503, 504}

This immediately mitigated the issue. A real intermittent 401 was subsequently caught by the existing retry mechanism, and the retry succeeded without interrupting the workflow.

### Steps to Reproduce

1. Run ComfyUI local portable and authenticate Comfy API Nodes using a static Comfy API key.

2. Run a workflow that repeatedly uses Comfy API endpoints. In my case the workflow uses Gemini API Nodes and image uploads through /customers/storage.

3. Let the workflow run repeatedly for a longer period. The issue is intermittent rather than deterministic on a specific request.

4. Eventually one request may return:

HTTP 401
{"message": "Invalid Comfy API key"}

5. The workflow fails with:

Unauthorized: Please login first to use this node.

6. Run the workflow again without changing the API key or logging in again.

7. Subsequent requests succeed normally with HTTP 200.

For comparison, adding HTTP 401 to `_RETRY_STATUS` causes the existing retry mechanism to retry the failed request. So far this has successfully recovered from the transient 401 and allowed the workflow to continue.

### Environment:

Comfy Info
ComfyUI 0.33.0
ComfyUI_frontend v1.49.6

System Info
OS: win32
Python Version: 3.13.14 (tags/v3.13.14:fd17997, Jun 10 2026, 13:03:48) [MSC v.1944 64 bit (AMD64)]
Embedded Python: true
PyTorch Version: 2.13.0+cu130
Arguments: ComfyUI\main.py --windows-standalone-build --disable-dynamic-vram
RAM Total: 255.82 GB
RAM Free: 237.07 GB
Templates Version: 0.11.43

Devices
- cuda:0 NVIDIA GeForce RTX 5090 : cudaMallocAsync (cuda)
VRAM Total: 31.84 GB
VRAM Free: 30.27 GB
Torch VRAM Total: 0 B
Torch VRAM Free: 0 B
- cuda:1 NVIDIA GeForce RTX 3090 : cudaMallocAsync (cuda)
VRAM Total: 24 GB
VRAM Free: 22.79 GB
Torch VRAM Total: 0 B
Torch VRAM Free: 0 B
- cuda:2 NVIDIA GeForce RTX 3090 : cudaMallocAsync (cuda)
VRAM Total: 24 GB
VRAM Free: 22.79 GB
Torch VRAM Total: 0 B
Torch VRAM Free: 0 B

### Debug Logs

```powershell
### Debug logs

#### 1. `/customers/storage` request fails with a transient 401

Request:

Timestamp: 2026-08-24T15:21:23.349239
Operation ID: POST_customers_storage_try1_9a71399f

POST https://api.comfy.org/customers/storage

Headers:
{
"Accept": "application/json",
"X-API-KEY": "***",
"Comfy-Env": "local-portable",
"Comfy-Usage-Source": "comfyui-frontend",
"Comfy-Core-Version": "0.33.0",
"Comfy-Job-Id": "6ef58e0f-0d09-4628-925b-0696c89ef3bd",
"Content-Type": "application/json"
}

Body:
{
"file_name": "dd7dc2e3-a8a9-4875-9f9b-ca04a9f11e2c.png"
}

Response for the same Operation ID:

Timestamp: 2026-08-24T15:21:27.429274
Operation ID: POST_customers_storage_try1_9a71399f

HTTP 401

{
"message": "Invalid Comfy API key"
}

ComfyUI then raises:

Unauthorized: Please login first to use this node.

#### 2. The same behavior also occurs on the Gemini proxy endpoint

Request:

Timestamp: 2026-08-24T15:24:40.530773
Operation ID: POST_proxy_vertexai_gemini_gemini-3.1-pro-preview_try1_e5d27a1e

POST https://api.comfy.org/proxy/vertexai/gemini/gemini-3.1-pro-preview

Headers:
{
"Accept": "application/json",
"X-API-KEY": "***",
"Comfy-Env": "local-portable",
"Comfy-Usage-Source": "comfyui-frontend",
"Comfy-Core-Version": "0.33.0",
"Comfy-Job-Id": "60745a08-603f-4984-a9bb-8877d2fb2c5e",
"Content-Type": "application/json"
}

Response for the same Operation ID:

Timestamp: 2026-08-24T15:24:44.518437
Operation ID: POST_proxy_vertexai_gemini_gemini-3.1-pro-preview_try1_e5d27a1e

HTTP 401

{
"message": "Invalid Comfy API key"
}

ComfyUI then raises:

Unauthorized: Please login first to use this node.

#### 3. Terminal traceback before applying the workaround

[ERROR] !!! Exception during processing !!! Unauthorized: Please login first to use this node.

[ERROR] Traceback (most recent call last):
File "...ComfyUI\execution.py", line 464, in execute
...
File "...ComfyUI\comfy_api_nodes\nodes_gemini.py", line 1127, in execute
parts.extend(await create_image_parts(cls, images))
...
File "...ComfyUI\comfy_api_nodes\util\upload_helpers.py", line 208, in upload_file_to_comfyapi
create_resp = await sync_op(
...
File "...ComfyUI\comfy_api_nodes\util\client.py", line 823, in _request_base
raise Exception(msg)

Exception: Unauthorized: Please login first to use this node.

#### 4. Workaround: retrying HTTP 401 successfully recovers the request

As a local test, I added `401` to `_RETRY_STATUS`:

_RETRY_STATUS = {401, 408, 500, 502, 503, 504}

The next real occurrence was caught by the existing retry mechanism:

[WARNING] HTTP POST https://api.comfy.org/customers/storage -> 401. Waiting 1.00s (retry 1 of 3).

The retry succeeded and the workflow continued normally.

No login, API-key change, or ComfyUI restart was required.
```

### Other

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in comfy_api_nodes/util/client.py by reading _RETRY_STATUS and _request_base, then run a workflow that repeatedly calls the documented Comfy API endpoints. Done means a transient HTTP 401 is handled by the existing retry path and the workflow continues without re-authentication.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.