Nodes/ComfyUI-MistralAI-API/Mistral AI completion
ComfyUI Node

Mistral AI completion

Have Mistral write your SD prompts from inside ComfyUI (API key required)

By randomnoner11·Created 2 years ago·Updated 9 months ago· 3
Mistral AI completion
  • image
  • response
model
temperature1.0
top_p0.9
max_tokens512
presence_penalty0.0
frequency_penalty0.0
promptYour response is directly used as a prompt: avoid quotation marks, brackets, etc! Focus on visually percievable descriptors, not touchy feely fluff. Give me a single SD prompt for the following:
context
random_seed

The first thing to know about InvokeMistralEndpoint is that the name is honest: it calls the Mistral AI API. It does not run a model locally, it does not need a GPU, and it will not work until you hand it a paid API key. What it buys you is a language model sitting right there in your graph - you describe a subject, it writes you a detailed Stable Diffusion prompt (or a Danbooru tag list, or anything else you ask for), and the result drops straight into your text encoder. This is the same thing people do with Claude or a local LM Studio server, minus the copy-paste.

It's a small, single-purpose pack from randomnoner11, published to the Comfy Registry, with no other dependencies to speak of - the source imports requests, Pillow and numpy, all of which ship with ComfyUI already. There isn't even a requirements.txt. If you have a Mistral key and a habit of staring at a blank prompt box, this is worth the two minutes of setup.

How it works

Under the hood it's one POST to https://api.mistral.ai/v1/chat/completions. There's no chat history, no hidden prompt injection - the author's selling point, and the source backs it up: your prompt string becomes a single user message, sent exactly as written. The node maintains nothing between runs.

It does a few useful things before that request goes out. The model dropdown is fetched live from the API when ComfyUI starts, so the list tracks Mistral's releases; vision-capable models get a 🖼️ emoji suffix. If that fetch fails or slows your startup, you can flip ENABLE_REMOTE_MODELS to False in nodes.py and it'll use a hardcoded list instead. If you feed it an image, it downscales to a 1024px longest side, encodes to JPEG/base64, and attaches it as a vision input - but only Pixtral models accept that.

The inputs that matter

The full input list looks intimidating, but you'll really touch four things:

  • model - pick from the dropdown. mistral-large-latest for the smartest writing, ministral-3b when you want it cheap, pixtral-* if you're sending an image.
  • prompt - your instruction. The default is a sensible "write me an SD prompt" system-ish prompt that you should edit to fit your checkpoint's prompting style.
  • max_tokens - default 512; tag lists and detailed descriptions fit fine in that.
  • context (optional) - a JSON string of chat messages, normally fed from the pack's companion node LoadFewShotPrompt, for few-shot prompting.

The rest - temperature (0–1.5), top_p, presence_penalty, frequency_penalty - are standard LLM sampling knobs passed straight to Mistral. The README's tip is worth keeping: with the smaller ministral models, nudging the penalties up beats fiddling with temperature for prompt-writing quality. random_seed is optional, and here's the subtle part: if you don't supply one, Mistral randomizes the seed server-side, so the same prompt can give you different output on every run. Supply a seed if you want reproducibility; wire it from a seed node if you want to keep two runs in sync.

Output

One output: response, a single STRING containing the raw API text. There's no built-in display, so wire it into a Show Text node (from ComfyUI-Custom-Scripts) to read it, or feed it straight into a CLIP Text Encode's positive-prompt input. That last move is the whole point - ask for a comma-separated tag list for your SDXL/Illustrious checkpoint, or a natural-language paragraph for a newer LLM-encoded model, and the response becomes the actual prompt.

Install

The easy path:

cd ComfyUI/custom_nodes
git clone https://github.com/randomnoner11/ComfyUI-MistralAI-API

Restart ComfyUI. Or use ComfyUI Manager and search for "MistralAI". No pip step, no model downloads - this is the rare pack with zero heavy dependencies.

Then the part people miss: create API-key.txt inside the node's folder and paste your key in it:

cd ComfyUI/custom_nodes/ComfyUI-MistralAI-API
echo "YOUR_MISTRAL_API_KEY" > API-key.txt

Where people get burned

  • Empty or missing API-key.txt. The repo ships with an empty key file, so the pack imports fine but every call returns a 401. Worse, the key is read at import time - if you edit the file, restart ComfyUI before testing, or the old (empty) key stays loaded.
  • Key file deleted → pack won't load. The key read happens at module import, so a missing file throws a FileNotFoundError and the whole pack fails. Keep that file.
  • Malformed context JSON. If the context string isn't a valid JSON array of {role, content} messages, the node silently ignores it and sends only your prompt. There's a warning in the console, not the UI.
  • Sending an image to a non-Pixtral model. The node doesn't stop you; the API will just reject the request.

The name is the trap in both directions - people assume "Mistral API" means it needs a key (true) and that it runs locally (false). It's a paid service call, plain and simple: great if you've got the key, useless if you don't.

Categoryutils/text

Inputs (10)

NameTypeDefaultDescription
modelCOMBO9 options: pixtral-large-latest, pixtral-12b-latest, ministral-3b-latest, ministral-8b-latest, ministral-14b-latest, open-mistral-nemo, +3
temperatureFLOAT1.00–1.5
top_pFLOAT0.90–1
max_tokensINT512
presence_penaltyFLOAT0.0-2–2
frequency_penaltyFLOAT0.0-2–2
promptSTRINGYour response is directly used as a prompt: avoid quotation marks, brackets, etc! Focus on visually percievable descriptors, not touchy feely fluff. Give me a single SD prompt for the following:
contextoptSTRINGUse Mistral AI prompt loader node to supply the context for few-shot prompting.
imageoptIMAGEOnly Pixtral models support image input.
random_seedoptINTIf you don't supply a fixed seed, it's randomized on the server.

Outputs (1)

NameTypeDescription
responseSTRING