Image with Mask

Using Image with Mask Endpoints

These endpoints are used in a similar way to other AI Server endpoints where you can provide:

  • RefId - provide a unique identifier to track requests
  • Tag - categorize like requests under a common group

In addition Queue requests can provide:

  • ReplyTo - URL to send a POST request to when the request is complete

Image with Mask

using var fsImage = File.OpenRead("files/comfyui_upload_test.png");
using var fsMask = File.OpenRead("files/comfyui_upload_test_mask.png");
var response = client.PostFilesWithRequest(new ImageWithMask {
        PositivePrompt = "A beautiful sunset over the ocean",
        NegativePrompt = "A pixelated, low-quality image"
    }, [
        new UploadFile("image", fsImage, "image"),
        new UploadFile("mask", fsMask, "mask")
    ]);

File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());

Queue Image with Mask

using var fsImage = File.OpenRead("files/comfyui_upload_test.png");
using var fsMask = File.OpenRead("files/comfyui_upload_test_mask.png");
var response = client.PostFilesWithRequest(new QueueImageWithMask {
        PositivePrompt = "A beautiful sunset over the ocean",
        NegativePrompt = "A pixelated, low-quality image"
    }, [
        new UploadFile("image", fsImage, "image"),
        new UploadFile("mask", fsMask, "mask")
    ]);

// Poll for Job Completion Status
GetArtifactGenerationStatusResponse status = new();
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
{
    status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId });
    Thread.Sleep(1000);
}
if (status.Results?.Count > 0)
{
    File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
}