Nodes/KIE.ai Nodes Next/Claude Sonnet 4.6
ComfyUI Node

Claude Sonnet 4.6

Building a Real Back-and-Forth With history_json

By felipederosilva·Created about a month ago·Updated a day ago· 3
Claude Sonnet 4.6
    • text
    • raw_json
    • credits_consumed
    • usage_json
    • credits_left
    ◄prompt►
    ◄system_prompt►
    ◄streamfalse►
    ◄tools_json[]►
    ◄history_json[]►
    ◄max_tokens4096►
    ◄thinkingfalse►
    ◄expert_override_json{}►

    history_json is the field everyone ignores on these LLM nodes, and it's the one that turns a prompt-rewriter into something closer to a collaborator. This node - the Sonnet 4.6 entry in the pack's Claude menu - is a fine place to learn it, because the widget that trips people up is the same on all ten Claude nodes.

    The two-message model

    Every Claude node here sends a messages array. history_json is that array; your prompt gets appended to it as the final {"role": "user"} turn. So:

    • One-shot: leave history_json at [], type your ask in prompt. The model sees exactly one message.
    • Multi-turn: put the prior exchange in history_json, put only the new question in prompt.
    • Pre-seeded: put your own {"role": "assistant"} turn in the history array and the model will continue in that voice. This is the trick for forcing a format - show it one correct answer and ask for more of the same.

    The mistake to avoid is putting the current question in both places. The model then answers twice, differently, and you'll blame the model.

    Why you'd bother

    Because prompt work is iterative, and re-typing everything you've established into a single prompt gets unwieldy fast. A realistic Comfy use: you're building a shot prompt. Turn one establishes the character. Turn two asks for a wide version. Turn three asks for the same scene at golden hour. Each turn adds one change and inherits everything else, instead of you trying to compress continuity into one paragraph. The KB's llm-in-comfyui.md describes the chained pattern that works well here - a narrow rewriting step feeding generation - and multi-turn is the same idea with memory.

    How it works

    Generated at startup from KIE's published Claude API page, this node assembles an Anthropic-shaped request (model, messages, stream, max_tokens, optional system, tools, thinkingFlag) and POSTs it to /claude/v1/messages on KIE's API host. history_json is parsed with a strict JSON parser and used verbatim; a malformed array fails the run before anything is sent. thinking maps to KIE's thinkingFlag, not Anthropic's budgeted thinking object - expert_override_json merges into the raw body if you need exact control.

    Inputs and outputs

    Required: prompt. The optional ones you'll use: history_json (JSON array of {"role": ..., "content": ...} messages), system_prompt (your standing instructions - it stays in force across turns, which is exactly what you want), max_tokens (default 4096, ceiling 131072 - conversation history eats into the window, so raise it when answers truncate), thinking. tools_json, stream and expert_override_json are the deep end.

    Outputs: text - the answer, wire it into a text-encode node, a parser, or another model's prompt socket. raw_json if the output looks wrong, usage_json for token accounting, and credits_consumed / credits_left floats with a credits receipt drawn on the node. Longer histories mean bigger bills per turn; that's the cost of context.

    No IMAGE input on Claude nodes here - multimodal goes through history_json or expert_override_json, with images uploaded first via KIE • Upload Image.

    Install

    ComfyUI Manager, search ComfyUI-KIE-Nodes-Next. Registry publishing is prepared but not shipped per the README, so:

    cd ComfyUI/custom_nodes
    git clone https://github.com/felipederosilva/ComfyUI-KIE-Nodes-Next
    cd ComfyUI-KIE-Nodes-Next
    pip install -r requirements.txt
    

    Restart, then Settings → KIE.ai Nodes Next → Connection and paste your key. KIE_API_KEY overrides the saved key. Python 3.10+, four small Python deps, no GPU, no weights.

    Common issues

    "Invalid history_json". It wants an array, exactly. {"role": "user", ...} on its own is an object, not an array, and fails. Also watch quoting - a pasted message with unescaped quotes inside a string is the most common real-world break.

    The model answers the same question twice. You put it in both history_json and prompt.

    Old turns keep influencing everything. That's memory working. If turn one said "keep it terse" and you can't shake terseness ten turns later, start a fresh node with a new history rather than arguing with it.

    Answers truncate mid-sentence. max_tokens - and history counts against it. Raise it or trim the array.

    First startup doesn't show the node. The library is built from KIE's docs index on first launch and the UI reloads once during the deep sync. Restart before troubleshooting.

    Every turn is a metered API call. A five-turn conversation is five bills. For high-volume prompt shaping, a local model in the graph costs nothing per call - the API node is for when you want the frontier model's judgement on the hard part.

    CategoryKIE Next/LLM/Claude/Sonnet

    Inputs (8)

    NameTypeDefaultDescription
    promptSTRINGUser prompt / message.
    system_promptoptSTRING—
    streamoptBOOLEANfalse—
    tools_jsonoptSTRING[]Optional function/tool definitions supported by this model endpoint.
    history_jsonoptSTRING[]Optional prior message/input array as JSON.
    max_tokensoptINT40961–131072—
    thinkingoptBOOLEANfalse—
    expert_override_jsonoptSTRING{}Expert-only request overrides. Normal use does not require this.

    Outputs (5)

    NameTypeDescription
    textSTRING—
    raw_jsonSTRING—
    credits_consumedFLOAT—
    usage_jsonSTRING—
    credits_leftFLOAT—