Where and what should I place my API key as?
Beginner here, sorry for that.
Where should I copy in the "set REPLICATE_API_TOKEN="r8_************"; python main.py"? Is it in a already current file in the "comfyui-replicate" folder or should I create a new file within there? And if so what should I call it?
Thank you for any help
I run a bat file and looks like this:
EDIT: Dont use quotation marks
set REPLICATE_API_TOKEN=**************************** .\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-build
So you add it before you run main.py
It seems to register but getting a 401 error ( was using quotation marks)
i added it to node.py
replicate.headers["Authorization"] = "Token *****"
You need to make sure that the API key is in an environment variable called REPLICATE_API_TOKEN
[START] Security scan [DONE] Security scan
ComfyUI-Manager: installing dependencies done.
** ComfyUI startup time: 2024-11-26 07:09:43.454578 ** Platform: Darwin ** Python version: 3.10.8 (v3.10.8:aaaf517424, Oct 11 2022, 10:14:40) [Clang 13.0.0 (clang-1300.0.29.30)] ** Python executable: /usr/local/bin/python3 ** ComfyUI Path: /Users/botansahin/pinokio/api/comfy.git/app ** Log path: /Users/botansahin/pinokio/api/comfy.git/app/custom_nodes/comfyui-replicate/comfyui.log
Prestartup times for custom nodes: 2.1 seconds: /Users/botansahin/pinokio/api/comfy.git/app/custom_nodes/ComfyUI-Manager
Traceback (most recent call last):
File "/Users/botansahin/pinokio/api/comfy.git/app/custom_nodes/comfyui-replicate/../../main.py", line 89, in
I get this error on Mac
i'm still getting the error -
Running black-forest-labs/flux-dev:0cce3d40843963ebc7b6d976778e977c8f3ae3d0980a37cb5204f8fa0289e3d2 with {'prompt': '', 'aspect_ratio': '1:1', 'prompt_strength': 0.8, 'num_outputs': 1, 'num_inference_steps': 28, 'guidance': 3.0, 'seed': 1944, 'output_format': 'webp', 'output_quality': 80, 'go_fast': True, 'megapixels': '1'}
HTTP Request: POST https://api.replicate.com/v1/predictions "HTTP/1.1 401 Unauthorized"
!!! Exception during processing !!! ReplicateError Details:
title: Unauthenticated
status: 401
detail: You did not pass a valid authentication token
Traceback (most recent call last):
File "C:\AI\ComfyUI\ComfyUI\execution.py", line 328, in execute
output_data, output_ui, has_subgraph = get_output_data(obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\ComfyUI\execution.py", line 203, in get_output_data
return_values = _map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\ComfyUI\execution.py", line 174, in _map_node_over_list
process_inputs(input_dict, i)
File "C:\AI\ComfyUI\ComfyUI\execution.py", line 163, in process_inputs
results.append(getattr(obj, func)(**inputs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\ComfyUI\custom_nodes\comfyui-replicate\node.py", line 191, in run_replicate_model
output = replicate.run(replicate_model, input=kwargs_without_force_rerun)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\python_embeded\Lib\site-packages\replicate\client.py", line 175, in run
return run(self, ref, input, use_file_output=use_file_output, **params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\python_embeded\Lib\site-packages\replicate\run.py", line 46, in run
prediction = client.predictions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\python_embeded\Lib\site-packages\replicate\prediction.py", line 497, in create
resp = self._client._request("POST", "/v1/predictions", json=body, **extras)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\AI\ComfyUI\python_embeded\Lib\site-packages\replicate\client.py", line 89, in _request
_raise_for_status(resp)
File "C:\AI\ComfyUI\python_embeded\Lib\site-packages\replicate\client.py", line 393, in _raise_for_status
raise ReplicateError.from_response(resp)
replicate.exceptions.ReplicateError: ReplicateError Details:
title: Unauthenticated
status: 401
detail: You did not pass a valid authentication token
Prompt executed in 0.44 seconds
SOLVED – First a Personal Note I resolved this issue for my issue, and I suspect this will be the issue for most folks running portable versions on windows... thanks to a helpful Discord community member who tipped me in the right direction to a solution. Unfortunately, Replicate's official documentation is not only lacking but also contains errors. Despite opening multiple GitHub issues, Discord queries, and support tickets over the past two months, we've received no responses from their support staff…. Just like all the other folks that asked the same question. It's frustrating that customers must solve problems caused by poor documentation without any assistance from the company. If you're facing similar issues, don’t rely on Replicate’s official channels. Turn to the community for help—they’re the real MVPs.
Steps to Resolve Replicate API Token Issues in ComfyUI (Portable Mode)
- Set the Windows Environment Variable: o Add the REPLICATE_API_TOKEN as a global Windows environment variable. o Note: This global variable is not automatically picked up by ComfyUI in portable mode.
- Test the Environment Variable with curl: o Use a simple curl command in the terminal to confirm the variable is being picked up and the API token works: cmd Copy code curl -X GET "https://api.replicate.com/v1/account" -H "Authorization: Bearer %REPLICATE_API_TOKEN%"
- Verify run_gpu.bat Picks Up the Variable: o Add a debug statement in ComfyUI/main.py to confirm the environment variable is accessible: python Copy code print(f"REPLICATE_API_TOKEN: {os.getenv('REPLICATE_API_TOKEN')}")
- Hard Code the API Key in node.py: o Modify the replicate.Client initialization in ComfyUI/custom_nodes/comfyui-replicate/node.py: python Copy code replicate = Client( headers={ "User-Agent": "comfyui-replicate/1.0.1", "Authorization": f"Token {os.getenv('REPLICATE_API_TOKEN')}" } )
Important Notes • Updates May Overwrite Changes: o If you update either ComfyUI or its custom nodes, the changes in main.py and node.py will be overwritten. You’ll need to reapply these fixes after updates.
There might be a simpler solution for some, other than hardcoding the api key. Check my comment in the other similar issue here:
https://github.com/replicate/comfyui-replicate/issues/7#issuecomment-2569931254
Hello, Newbie and first install of comfyUI App on mac. My API key was already set in my .zshrc for some dev project. Unfortunately I got an Authorization missing errors when trying to run a model from the app.
To get it working I just added this line in the node.py
# Explicitly set the API token if not already in environment
if "REPLICATE_API_TOKEN" not in os.environ:
os.environ["REPLICATE_API_TOKEN"] = "HERE YOUR API KEY"
import os
import json
from PIL import Image
from io import BytesIO
import io
from torchvision import transforms
import torch
import base64
import time
import torchaudio
import soundfile as sf
from replicate.client import Client
from .schema_to_node import (
schema_to_comfyui_input_types,
get_return_type,
name_and_version,
inputs_that_need_arrays,
)
# Explicitly set the API token if not already in environment
if "REPLICATE_API_TOKEN" not in os.environ:
os.environ["REPLICATE_API_TOKEN"] = "HERE YOUR API KEY"
replicate = Client(headers={"User-Agent": "comfyui-replicate/1.0.1"})
I dont know why I should do this but it works now for me!