Nodes/Duanyll Nodepack/Create OpenAI Client
ComfyUI Node

Create OpenAI Client

The key-and-transport hub for gpt-image in ComfyUI

By Duanyll·Created about a year ago·Updated 4 months ago· 2
Create OpenAI Client
    • client
    api_key
    base_urlhttps://api.openai.com/v1
    timeout300
    image_upload_modemultipart_form
    multipart_image_fieldimage[]
    transportrequests
    curl_pathcurl

    Create OpenAI Client is the credentials-and-transport factory that powers the pack's paid-image nodes (OpenAI Image Edit and OpenAI Image Generation). It doesn't generate anything itself - it assembles an OPENAI_CLIENT object carrying your API key, endpoint, timeout, and the low-level decisions about how images get uploaded, then hands that object to the nodes that actually call the API. It's the config hub, and getting it right is the difference between working gpt-image calls and an afternoon of confusing 400s.

    The reason this node exists as a separate step is that OpenAI's image endpoints have genuinely fiddly transport requirements. gpt-image uploads can go as JSON-encoded base64 or as multipart/form-data; some OpenAI-compatible proxies accept one and reject the other; and the multipart field name for the image is not standardized (image[] vs image). This node surfaces all of that as explicit choices instead of hardcoding it, which is exactly what a pack author who fought a third-party proxy would build.

    The inputs

    • api_key - your key.
    • base_url - defaults to https://api.openai.com/v1. Point it at any OpenAI-compatible gateway.
    • timeout - request timeout in seconds (default 300). Image API calls are slow; don't set it too low.
    • image_upload_mode - multipart_form (default) or json_base64. Flip this when a proxy rejects your requests.
    • multipart_image_field - image[] (default) or image. Only relevant in multipart mode; another proxy-compat switch.
    • transport - requests (default) or curl. curl shells out to a real curl binary - a fallback for environments where Python's HTTP stack is being blocked or proxied weirdly. curl_path lets you point at the binary (default curl).

    One output: client, an OPENAI_CLIENT, which wires into OpenAI Image Edit or OpenAI Image Generation.

    Install

    The pack standard:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Duanyll/duanyll_nodepack
    cd duanyll_nodepack && pip install -r requirements.txt
    

    or ComfyUI Manager → "Duanyll Nodepack" → install → restart. The node itself needs only requests; the pack's other requirements (OpenCV, kornia, insightface, matplotlib, Volcengine SDK) install alongside.

    Gotchas

    The same secret-in-workflow warning as the S3 client: the API key is plain text in your workflow JSON, so don't share the file. And the transport options exist for a reason - if you're behind a corporate proxy or using a non-OpenAI gateway, the defaults may simply not work, and the fix is usually flipping image_upload_mode or switching to curl before you blame the API. This is the most "pack author learned the hard way" node in the bunch, and for anyone actually running gpt-image workflows, those hard-won switches are the value. It's not glamorous, but it's the difference between a working pipeline and a dead one.

    Categoryduanyll/models/openai

    Inputs (7)

    NameTypeDefaultDescription
    api_keySTRING
    base_urlSTRINGhttps://api.openai.com/v1
    timeoutINT3001–3600
    image_upload_modeCOMBOmultipart_form2 options: json_base64, multipart_form
    multipart_image_fieldCOMBOimage[]2 options: image[], image
    transportCOMBOrequests2 options: requests, curl
    curl_pathSTRINGcurl

    Outputs (1)

    NameTypeDescription
    clientOPENAI_CLIENT