Nodes/ComfyUI OpenAI API/OpenAI API - Frequency Penalty
ComfyUI Node

OpenAI API - Frequency Penalty

Stop the model repeating itself, word for word

By hekmon·Created about a year ago·Updated 9 months ago· 46
OpenAI API - Frequency Penalty
  • other_options
  • Options
frequency_penalty0.0

Every LLM has a bad habit: when it gets stuck, it starts repeating the same sentence verbatim, like a broken record that's also out of ideas. OAIAPI_FrequencyPenalty is the pack's remedy. It penalizes a token based on how often it has already appeared in the text so far, so the longer a model drones on about one thing, the more the sampler pushes it somewhere else. The author's own description nails it: positive values decrease "the model's likelihood to repeat the same line verbatim."

How it works

Like every option node in this pack, it packs a float into an OAIAPI_OPTIONS payload that the Chat Completion node extracts and sends as the frequency_penalty parameter. The range is −2.0 to 2.0 with a 0.1 step, default 0 (off). Positive values punish repetition, negative values actively encourage it - handy if you're prompting for a repeated format or chant, which is basically never, but now you know the dial goes both ways.

The difference from the pack's presence penalty node is worth getting straight, because people conflate them: frequency penalty scales with how many times a token has appeared (repeated words get hit harder each time), while presence penalty is a flat penalty for having appeared at all. Frequency kills verbatim loops; presence nudges the model onto new topics.

The inputs and output

  • frequency_penalty - the only widget. A good starting point is 0.3–0.5 if a model is looping on long generations. For short prompt-rewrite calls you rarely need it.
  • other_options (optional) - chain point for other option nodes; the last one to set a key wins.
  • Output: Options (OAIAPI_OPTIONS), wired into 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: ComfyUI Manager → search "OpenAI API" → install, or

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

then restart. Only new dependency is openai; no models to download.

Where people get burned

Cranking it too high. Above ~1.5 the model gets evasive and dances around the point because every obvious word keeps getting penalized - you trade repetition for word salad. Also: like most sampling knobs, this one's best-effort across OpenAI-compatible servers, and smaller local models through Ollama react more erratically than the cloud models. If a long classification or captioning call keeps coming back with a repeated tail, 0.4 frequency penalty plus a max_tokens cap is a much better fix than fighting the output in post.

CategoryOpenAI API/Options

Inputs (2)

NameTypeDefaultDescription
frequency_penaltyFLOAT0.0-2–2Number between -2.0 and 2.0
other_optionsoptOAIAPI_OPTIONSOthers options to merge with

Outputs (1)

NameTypeDescription
OptionsOAIAPI_OPTIONSMerged options to forward