TsgcHTTP_API_OpenAIMethods › CreateImageEdit

CreateImageEdit Method

Edits an existing image using a text prompt and an optional transparency mask

Syntax

function CreateImageEdit(const aRequest: TsgcOpenAIClass_Request_Image_Edit) : TsgcOpenAIClass_Response_Image_Edit;

Parameters

NameTypeDescription
aRequestconst TsgcOpenAIClass_Request_Image_EditRequest payload containing the source image, optional mask, edit prompt, model, size and result format.

Return Value

Parsed response object exposing the edited image(s) as URLs or base64-encoded PNG data. (TsgcOpenAIClass_Response_Image_Edit)

Remarks

Issues a multipart/form-data POST to /v1/images/edits. Supply the original PNG and, when using DALL-E 2, a PNG mask with transparent pixels marking the region to regenerate. The text prompt describes how the masked area should be filled; unmasked pixels are preserved. Works with DALL-E 2 (with mask) and gpt-image-1 (mask optional), producing one or more edited images in the requested size and format.

Example

oRequest := TsgcOpenAIClass_Request_Image_Edit.Create;
try
  oRequest.Model := 'gpt-image-1';
  oRequest.Image := 'C:\images\photo.png';
  oRequest.Mask := 'C:\images\mask.png';
  oRequest.Prompt := 'Replace the sky with a colorful aurora borealis';
  oResponse := oAPI.CreateImageEdit(oRequest);
  ShowMessage(oResponse.Data[0].Url);
finally
  oRequest.Free;
end;

Back to Methods