TsgcHTTP_API_OpenAIMethods › CreateImageVariation

CreateImageVariation Method

Generates prompt-free variations of an existing image using the OpenAI Images endpoint

Syntax

function CreateImageVariation(const aRequest : TsgcOpenAIClass_Request_Image_Variation) : TsgcOpenAIClass_Response_Image_Variation;

Parameters

NameTypeDescription
aRequestconst TsgcOpenAIClass_Request_Image_VariationRequest payload holding the source image, number of variations, size and response format.

Return Value

Parsed response object exposing the generated variations as URLs or base64-encoded PNG data. (TsgcOpenAIClass_Response_Image_Variation)

Remarks

Issues a multipart/form-data POST to /v1/images/variations. The supplied PNG must be square and no larger than 4 MB; OpenAI returns alternate renditions that preserve the general composition while changing style and details. Only DALL-E 2 supports this endpoint; no textual prompt is accepted. Use n to request up to ten variations per call and select url or b64_json via response_format.

Example

oRequest := TsgcOpenAIClass_Request_Image_Variation.Create;
try
  oRequest.Image := 'C:\images\logo.png';
  oRequest.N := 3;
  oRequest.Size := '512x512';
  oResponse := oAPI.CreateImageVariation(oRequest);
  ShowMessage('Got ' + IntToStr(oResponse.Data.Count) + ' variations');
finally
  oRequest.Free;
end;

Back to Methods