Nodes/ComfyUI OpenAI API/OpenAI API - Top P
ComfyUI Node

OpenAI API - Top P

Nucleus sampling, minus the jargon

By hekmon·Created about a year ago·Updated 9 months ago· 46
OpenAI API - Top P
  • other_options
  • Options
top_p1.00

OAIAPI_TopP is the pack's answer to "the next token should be chosen from a smaller, more confident pool." It's called nucleus sampling, and it works like this: instead of letting the model pick from every possible next token, you only let it consider the tokens that make up the top top_p probability mass. Set it to 0.1 and the model only picks from tokens whose combined probability is the top 10% - which reads, in practice, as "sticking to the safest, most likely continuations." Set it to 1.0 (the default) and every token is in the pool, which is effectively off.

How it works

Like the other option nodes, it stuffs a value into an OAIAPI_OPTIONS payload that the Chat Completion node later extracts and sends as the top_p parameter. The slider runs 0.0 to 1.0 with a 0.01 step, default 1.0. Where temperature scales the whole probability distribution, top_p chops off the tail - different mechanism, similar effect on "how adventurous is this model." The author's own tooltip says it plainly: 0.1 means only the tokens comprising the top 10% probability mass are considered.

The inputs and output

  • top_p - the only real widget. Low (0.1–0.5): focused, less repetition, more deterministic-feeling. High (0.9–1.0): nearly the full distribution, closer to default behavior.
  • other_options (optional) - merge point for chaining other option nodes.
  • Output: Options (OAIAPI_OPTIONS), which feeds the next option node or Chat Completion's options input.

Installing it

It's one of the ten nodes in the comfyui-openai-api pack, so install is the pack install: search "OpenAI API" in ComfyUI Manager, or

cd ComfyUI/custom_nodes
git clone https://github.com/hekmon/comfyui-openai-api

restart, done. Only new dependency is openai; nothing to download model-wise.

The honest take

For most ComfyUI LLM workflows - prompt rewriting, image classification, branching on a one-word answer - top_p is the option node you'll touch least. It's the parameter people mention on the API docs page and rarely tune in real life, and OpenAI's guidance explicitly says not to use it alongside temperature. Where it earns its keep is when a model keeps meandering into weird tokens at your preferred temperature: drop top_p to around 0.8 and you get most of the creativity with a much smaller tail of nonsense. The pack even ships it as a dedicated node because the parameter is that cheap to add - but if you're only going to wire one randomness control, temperature does more per click. This one's the fine-tune, not the main knob.

CategoryOpenAI API/Options

Inputs (2)

NameTypeDefaultDescription
top_pFLOAT1.000–10.1 means only the tokens comprising the top 10% probability mass are considered
other_optionsoptOAIAPI_OPTIONSOthers options to merge with

Outputs (1)

NameTypeDescription
OptionsOAIAPI_OPTIONSMerged options to forward