Sample code for 30+ languages & platforms
Delphi DLL

Simple AI Image Generation

See more AI Examples

Create an image by providing a text description.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, Ai, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
ai: HCkAi;
askParams: HCkJsonObject;
bdImageData: HCkBinData;

begin
success := False;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

ai := CkAi_Create();

CkAi_putProvider(ai,'openai');

// Use your provider's API key.
CkAi_putApiKey(ai,'MY_API_KEY');

// Choose a model.
CkAi_putModel(ai,'gpt-5');

askParams := CkJsonObject_Create();
CkJsonObject_UpdateString(askParams,'image.output_format','jpeg');
CkJsonObject_UpdateString(askParams,'image.size','1024x1024');
CkJsonObject_UpdateString(askParams,'image.quality','low');
CkAi_SetAskParams(ai,askParams);

CkAi_InputAddText(ai,'Generate a small, cute illustration of a gray tabby cat hugging a happy otter wearing an orange scarf');

// Ask the AI for image output.
success := CkAi_Ask(ai,'image');
if (success = False) then
  begin
    Memo1.Lines.Add(CkAi__lastErrorText(ai));
    Exit;
  end;

// Get the image response data.
bdImageData := CkBinData_Create();
success := CkAi_GetOutputBd(ai,bdImageData);
if (success = False) then
  begin
    Memo1.Lines.Add(CkAi__lastErrorText(ai));
    Exit;
  end;

CkBinData_WriteFile(bdImageData,'c:/aaworkarea/out.jpg');

Memo1.Lines.Add('Success.');

CkAi_Dispose(ai);
CkJsonObject_Dispose(askParams);
CkBinData_Dispose(bdImageData);

end;