ComfyUI_NAIDGenerator icon indicating copy to clipboard operation
ComfyUI_NAIDGenerator copied to clipboard

Keep Running the 401 Error even placed the .ENV file and API Key

Open ZH79doc opened this issue 6 months ago • 2 comments

As the title stated, I keep getting 401 error even with .ENV and API Key placed correctly.

Asked GPT to see if anything went wrong and it says:

The main function generate_image() does not call get_access_token() — it relies on the token being passed in from outside.

From your traceback earlier:

generate_image(self.access_token, ...)

So, if self.access_token is not loaded via get_access_token(), the .env file is never read.

Then it sugguested to edit the following in nodes.py:

zipped_bytes = generate_image(self.access_token, positive, model, action, params, timeout, retry)

to:

from .utils import get_access_token # Add this at top if not already imported

access_token = get_access_token() zipped_bytes = generate_image(access_token, positive, model, action, params, timeout, retry)

I edited as it says and now it works!

ZH79doc avatar Jun 20 '25 19:06 ZH79doc

Thanks for your tips. I have a question: where do you put the .env file? I don't know it's exact location. And the .env file is just a text document with the line NAI_ACCESS_TOKEN= My access token, right?

son-2004 avatar Nov 15 '25 12:11 son-2004

.env should be in "ComfyUI" folder, and set token as NAI_ACCESS_TOKEN=pst-...

bedovyy avatar Nov 15 '25 16:11 bedovyy