Sample code for 30+ languages & platforms
Lianja

Simple AI Image Generation

See more AI Examples

Create an image by providing a text description.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loAi = createobject("CkAi")

loAi.Provider = "openai"

// Use your provider's API key.
loAi.ApiKey = "MY_API_KEY"

// Choose a model.
loAi.Model = "gpt-5"

loAskParams = createobject("CkJsonObject")
loAskParams.UpdateString("image.output_format","jpeg")
loAskParams.UpdateString("image.size","1024x1024")
loAskParams.UpdateString("image.quality","low")
loAi.SetAskParams(loAskParams)

loAi.InputAddText("Generate a small, cute illustration of a gray tabby cat hugging a happy otter wearing an orange scarf")

// Ask the AI for image output.
llSuccess = loAi.Ask("image")
if (llSuccess = .F.) then
    ? loAi.LastErrorText
    release loAi
    release loAskParams
    return
endif

// Get the image response data.
loBdImageData = createobject("CkBinData")
llSuccess = loAi.GetOutputBd(loBdImageData)
if (llSuccess = .F.) then
    ? loAi.LastErrorText
    release loAi
    release loAskParams
    release loBdImageData
    return
endif

loBdImageData.WriteFile("c:/aaworkarea/out.jpg")

? "Success."


release loAi
release loAskParams
release loBdImageData