Nodes/comfyui-aichat/OpenAI 文件上传器
ComfyUI Node

OpenAI 文件上传器

Upload a file to an OpenAI-compatible API, file_id included

By spawner1145·Created about a year ago·Updated 10 days ago· 3
OpenAI 文件上传器
  • api_instance
  • content_item
  • file_id
file_selector
use_absolute_pathfalse
absolute_path_override/path/to/your/file.pdf
display_name

The file-fed vision path

OpenAIFileUploader takes a file from your ComfyUI input folder (or an absolute path), uploads it through the provider's Files API, and returns a file_id the model can reference in a message. It's the OpenAI-compatible equivalent of the Gemini File Uploader, and it's the right tool for PDFs, data files, and anything too big or too awkward to base64 into a prompt. The pack's own example workflow pairs it with Lumina-style generation, where you feed a reference document.

How it works

You need an api_instance from OpenAIApiLoader. The node reads the file bytes, guesses the MIME type from the extension, and calls client.files.create(file=..., purpose="user_data"). Here's the part worth knowing: not every OpenAI-compatible endpoint implements the Files API the way OpenAI does. The code has a fallback - if the SDK chokes on a non-standard response, it parses the raw JSON looking for a data.id and still returns you a file_id. That's the author acknowledging how messy the compatible-endpoint world really is.

The fields that matter

  • file_selector - dropdown of files in your input directory.
  • use_absolute_path / absolute_path_override - toggle for files outside the input folder.
  • display_name - optional; defaults to the filename.
  • api_instance - required, from the loader.

Outputs

content_item - an OAI_CONTENT_ITEM wrapping {"input_file": {"file_id": ...}}, for the Chat node or a connector. file_id - the raw id string.

Where people get burned

  • The provider must actually have a Files API. This is the real trap: local endpoints like Ollama or LM Studio don't implement file uploads at all, so this node hard-errors there. It only works with hosts that support the Files API - OpenAI proper, ModelScope, and a few others.
  • MIME guessing again. Unknown extensions fall back to application/octet-stream, which some models reject. Give files proper extensions.
  • The file must exist at the resolved path; the dropdown only lists input-dir files, so absolute paths are on you.
  • Uploaded files are stored on the provider's side - that's a storage surface with its own cost and cleanup obligations.
  • For images, prefer the inline encoder. This node is for files - documents and data - not for a quick look at a render.

Install

With the pack via ComfyUI Manager (search "comfyui-aichat") or:

cd ComfyUI/custom_nodes
git clone https://github.com/spawner1145/comfyui-aichat

Restart ComfyUI. Dependencies: openai, httpx, PyYAML. No model downloads, just an API key from a provider that supports file uploads.

CategoryOpenAI API/Content

Inputs (5)

NameTypeDefaultDescription
api_instanceOPENAI_API_INSTANCE
file_selectorCOMBO1 options: example.png
use_absolute_pathBOOLEANfalse
absolute_path_overrideSTRING/path/to/your/file.pdf
display_nameSTRING

Outputs (2)

NameTypeDescription
content_itemOAI_CONTENT_ITEM
file_idSTRING