HF_QuestionAnswer
Ask an LLM from inside ComfyUI — no GPU, no model download, just an API call
- STRING
The name is a small lie and the pack title spells "serverless" wrong - Servelress - but the idea is honest and genuinely handy. HF_QuestionAnswer runs no model on your machine at all. It takes a question and a context, fires them at a Hugging Face serverless Inference API endpoint, and returns whatever the LLM says as a plain string. Zero VRAM, zero downloads, zero transformers import errors. If you've ever wanted to enhance a prompt with an LLM pass but didn't want to run Llama locally on the same GPU that's already busy denoising, this is the cheap way in.
It lives in the Huggingface Api Serverless pack (repo: alexgenovese/ComfyUI_HF_Servelress_Inference), which is worth knowing about because the same pack also ships the Joy-Caption nodes. Those run locally and are heavy; this one is the opposite - it needs nothing but an internet connection and a token.
How it works
Look at the source and there's no magic to find. The node builds a two-message chat: your context becomes the system message ("LLM Instruction for the model", per the README) and your question becomes the user message. Then it calls chat_completion on Hugging Face's InferenceClient with max_tokens=5000, and returns the model's reply. That's the whole mechanism - an HTTP request wearing a node costume.
Two consequences follow from reading the code rather than guessing. First, the endpoint has to be a chat-completions-compatible model - not every repo on the Hub qualifies. Second, the empty-token guard is a trap: if you leave hf_token blank it raises an error whose message reads "found this in ENV HF_AUTH_TOKEN" - which sounds like a fallback to an environment variable. It isn't. The code never actually reads that env var as a token; you just get a KeyError if it's unset. Paste a real token into the field. Speaking of which, this node sends your token to Hugging Face every run, so use a token without write scope - and never share a workflow that has one baked into the saved JSON, because ComfyUI stores node inputs in the graph.
The inputs that matter
All four inputs are required, and there are only four:
- hf_token - your Hugging Face token, from huggingface.co/settings/tokens.
- endpoint - the repo id of a model that has the serverless Inference API enabled, e.g.
meta-llama/Meta-Llama-3-8B-Instruct. - question - what you're actually asking (multiline).
- context - the instructions/background for the model (multiline). This is your "system prompt" slot, so it's where prompt-enhancement instructions go.
The single output is a STRING - the model's answer. Wire it into any string input downstream: a text-concatenate node feeding your checkpoint's positive prompt, a prompt-rewrite stage, whatever. It's just text.
Install
Install via ComfyUI Manager (search "Huggingface Api Serverless"), or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/alexgenovese/ComfyUI_HF_Servelress_Inference
cd ComfyUI_HF_Servelress_Inference
pip install -r requirements.txt
Then restart ComfyUI. The requirements file is refreshingly small - just huggingface_hub - so there's none of the dependency hell the rest of the ecosystem makes famous. You still need to be online and have a Hugging Face account with a token.
Common issues
The README's own warning is the one that'll bite you: the serverless Inference API only runs models 10GB or below, and it "fails for random reasons on different models." That's the nature of a shared free tier - cold starts, rate limits, and models that just refuse to load on any given day. Practical takeaways: stick to smaller instruct models, expect the occasional transient failure (a re-run often just works), and if the endpoint you want keeps erroring, check on the model's Hub page that "Inference API" is actually enabled for it. If you're getting auth errors, it's your token; if it's mid-generation failures on a model over 10GB, that's the ceiling, not your fault.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| hf_token | STRING | — | |
| endpoint | STRING | — | |
| question | STRING | — | |
| context | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |