Skip to content

clients.openai #

Example: Creating an Image


import incubaid.herolib.clients.openai

mut client:= openai.get()! //will be the default client, key is in `AIKEY` on environment variable or `OPENROUTER_API_KEY`

resp := client.images.create_image(
    prompt: 'A futuristic city at sunset',
    n: 1,
    size: '1024x1024'
)

if resp.data.len > 0 {
    println('Image created. URL: ${resp.data[0].url}')
} else {
    eprintln('Failed to create image.')
}

fn (OpenAIAlias) create_image #

fn (mut f OpenAIAlias) create_image(args ImageCreateArgs) !Images

Create new images generation given a prompt the amount of images returned is specified by num_images

fn (OpenAIAlias) create_edit_image #

fn (mut f OpenAIAlias) create_edit_image(args ImageEditArgs) !Images

edit images generation given a prompt and an existing image image needs to be in PNG format and transparent or else a mask of the same size needs to be specified to indicate where the image should be in the generated image the amount of images returned is specified by num_images

fn (OpenAIAlias) create_variation_image #

fn (mut f OpenAIAlias) create_variation_image(args ImageVariationArgs) !Images

create variations of the given image image needs to be in PNG format the amount of images returned is specified by num_images

enum ImageRespType #

enum ImageRespType {
	url
	b64_json
}

enum ImageSize #

enum ImageSize {
	size_256_256
	size_512_512
	size_1024_1024
}

struct ImageCreateArgs #

@[params]
struct ImageCreateArgs {
pub mut:
	prompt     string
	num_images int
	size       ImageSize
	format     ImageRespType
	user       string
}

struct ImageEditArgs #

struct ImageEditArgs {
pub mut:
	image_path string
	mask_path  string
	prompt     string
	num_images int
	size       ImageSize
	format     ImageRespType
	user       string
}

struct ImageRequest #

struct ImageRequest {
pub mut:
	prompt          string
	n               int
	size            string
	response_format string
	user            string
}

struct ImageResponse #

struct ImageResponse {
pub mut:
	url      string
	b64_json string
}

struct ImageVariationArgs #

struct ImageVariationArgs {
pub mut:
	image_path string
	num_images int
	size       ImageSize
	format     ImageRespType
	user       string
}

struct Images #

struct Images {
pub mut:
	created int
	data    []ImageResponse
}