Values

DALL_E_2

DALL_E_2: Str "dall-e-2"

DALL_E_3

DALL_E_3: Str "dall-e-3"

SIZE_1024

SIZE_1024: Str "1024x1024"

SIZE_1024_1792

SIZE_1024_1792: Str "1024x1792"

SIZE_1792_1024

SIZE_1792_1024: Str "1792x1024"

SIZE_256

SIZE_256: Str "256x256"

SIZE_512

SIZE_512: Str "512x512"

Functions

create-image

fn (prompt: Str): Str | ::openai::api/HttpError
fn (prompt: Str, opts: Map): Str | ::openai::api/HttpError
fn (prompt: Str, size: Str?): Str | ::openai::api/HttpError
fn (prompt: Str, size: Str?, opts: Map): Str | ::openai::api/HttpError

Simple image generation - returns the URL of the generated image.

Example

url ::openai::images/create-image("A sunset over mountains")
// "https://..."

detect-format

fn (path: Str): Str?

Detect image format from file path extension.

Example

::openai::images/detect-format("output/cat.png")  // "png"

edit

fn (request: EditImageRequest): CreateImageResponse | ::openai::api/HttpError
fn (request: EditImageRequest, opts: Map): CreateImageResponse | ::openai::api/HttpError

Edit an image with a prompt (inpainting).

Example

response ::openai::images/edit({
    image: "path/to/image.png",
    prompt: "Add a red hat to the person",
    mask: "path/to/mask.png"
})

generate

fn (request: CreateImageRequest): CreateImageResponse | ::openai::api/HttpError
fn (request: CreateImageRequest, opts: Map): CreateImageResponse | ::openai::api/HttpError

Generate images from a text prompt using DALL-E.

Returns a CreateImageResponse with a data array containing either URLs or base64 data. Defaults to DALL-E 3 if no model is specified.

Example - URL response (default)

response ::openai::images/generate(::openai::images/CreateImageRequest({
    prompt: "A simple red circle on a white background",
    model: "dall-e-2",
    size: "256x256",
    n: 1
}))

image response.data[0]
image.url // => "https://oaidalleapi..."

Example - Base64 response

response ::openai::images/generate(::openai::images/CreateImageRequest({
    prompt: "A cat wearing a spacesuit",
    model: "dall-e-3",
    response_format: "b64_json"
}))

base64-data response.data[0].b64_json

generate-batch-to-files

fn (path-template: Str, prompt: Str, count: Int): ::ai::media/AIMediaBatch
fn (path-template: Str, prompt: Str, count: Int, opts: Map): ::ai::media/AIMediaBatch

Generate multiple images and save them to files.

Returns an AIMediaBatch with all generated AIMedia.Image items.

The path should include a {n} placeholder that will be replaced with the image index.

Example

batch ::openai::images/generate-batch-to-files("uploads/image-{n}.png", "A beautiful landscape", 3)
// Generates: uploads/image-0.png, uploads/image-1.png, uploads/image-2.png

batch.succeeded // => 3
batch.failed    // => 0
first(batch.items).media.file.path // => "uploads/image-0.png"

Note: DALL-E 3 only supports n=1, so this will make multiple API calls.

generate-to-file

fn (path: Str, prompt: Str): ::ai::media/AIMedia | ::openai::api/HttpError
fn (path: Str, prompt: Str, opts: Map): ::ai::media/AIMedia | ::openai::api/HttpError
fn (path: Str, request: CreateImageRequest): ::ai::media/AIMedia | ::openai::api/HttpError
fn (path: Str, request: CreateImageRequest, opts: Map): ::ai::media/AIMedia | ::openai::api/HttpError

Generate an image and save it to a file.

Returns an AIMedia.Image with file metadata and AI generation details.

Example

result ::openai::images/generate-to-file("uploads/city.png", "A futuristic city at sunset")

match result {
    ::ai::media/AIMedia.Image => {
        result.media.file.path  // => "uploads/city.png"
        result.media.file.size  // => 123456
        result.prompt           // => "A futuristic city at sunset"
        result.revised_prompt   // => "A detailed futuristic city..."
        result.provider         // => "openai"
    }
}

With options

result ::openai::images/generate-to-file("output/cat.png", {
    prompt: "A cat wearing a spacesuit",
    model: "dall-e-3",
    quality: "hd",
    style: "vivid"
})

parse-size

fn (size: Str?): Map

Parse size string like '1024x1024' into width/height.

Example

::openai::images/parse-size("1024x1536")  // {width: 1024, height: 1536}
::openai::images/parse-size(null)  // {width: null, height: null}

variation

fn (request: VariationImageRequest): CreateImageResponse | ::openai::api/HttpError
fn (request: VariationImageRequest, opts: Map): CreateImageResponse | ::openai::api/HttpError

Create variations of an image.

Example

response ::openai::images/variation({
    image: "path/to/image.png",
    n: 3
})

Types

ApiImageData

ApiImageData type {
    url: Str?,
    b64_json: Str?,
    revised_prompt: Str?
}

CreateImageRequest

CreateImageRequest type {
    prompt: Str,
    model: Str?,
    n: Int?,
    quality: Quality?,
    response_format: ResponseFormat?,
    size: Size?,
    style: Style?,
    user: Str?
}

CreateImageResponse

CreateImageResponse type {
    created: Int,
    data: Vec<ApiImageData>
}

EditImageRequest

EditImageRequest type {
    image: Str,
    prompt: Str,
    mask: Str?,
    model: Str?,
    n: Int?,
    size: Str?,
    response_format: ResponseFormat?,
    user: Str?
}

Quality

Quality type "standard" | "hd" | "low" | "medium" | "high" | "auto"

ResponseFormat

ResponseFormat type "url" | "b64_json"

Size

Size type "auto" | "1024x1024" | "1536x1024" | "1024x1536" | "256x256" | "512x512" | "1792x1024" | "1024x1792"

Style

Style type "vivid" | "natural"

VariationImageRequest

VariationImageRequest type {
    image: Str,
    model: Str?,
    n: Int?,
    size: Str?,
    response_format: ResponseFormat?,
    user: Str?
}