openai.ImageClient

The OpenAI image-generation client: POST {base_url}/images/generations.

Reference version

Signature

class openai.ImageClient

The OpenAI image-generation client: POST {base_url}/images/generations.

client "openai-images/gpt-image-1" in an LLM function constructs this class. Its output type is media — -> image, -> image[], -> image?, -> string | image — which the runner builds from the turn's media blocks (ai/runner.baml) instead of parsing text.

function DrawLamp(subject: string) -> image {
    client "openai-images/gpt-image-1"
    prompt `A studio photograph of ${subject}.`
}

The endpoint takes a text prompt only: media inputs are rejected (image editing is a different, multipart endpoint) and tools are not supported.

Source:<builtin>/openai/images.bamlbytes 6907172

Fields

model

string

api_key

ai.Credential | null

base_url

ai.Credential | null

n

int | null

size

string | null

quality

string | null

background

string | null

output_format

string | null

output_compression

int | null

moderation

string | null

style

string | null

user

string | null

response_format

string | null

request_body

baml.json.json | null

headers

map<string, string> | null

query_params

map<string, string> | null

capture_wire

bool

Static methods

function

new

(
model: string = …,
api_key: ai.Credential | null = …,
base_url: ai.Credential | null = …,
n: int | null = …,
size: string | null = …,
quality: string | null = …,
background: string | null = …,
output_format: string | null = …,
output_compression: int | null = …,
moderation: string | null = …,
style: string | null = …,
user: string | null = …,
response_format: string | null = …,
request_body: baml.json.json | null = …,
headers: map<string, string> | null = …,
query_params: map<string, string> | null = …,
capture_wire: bool = …
) -> openai.ImageClient

Creates a client. Construction reads no environment variable, so declaring one is always safe; credentials and endpoints resolve when a request is built.

Instance methods

function

resolved_api_key

(
self
) -> string throws baml.errors.Io | baml.errors.ParseError | ai.errors.InvalidRequest

The request-time credential: an explicit value, else the provider's canonical one. A missing credential is a catchable ai.errors.InvalidRequest rather than a panic, so the caller's catch_all can fall back to another client.

function

resolved_base_url

(self) -> string | null throws baml.errors.Io | baml.errors.ParseError

The request-time base URL, or null for the provider default.

Implementations

ai.Client for openai.ImageClient

Instance methods

function

id

(self) -> string
function

invoke

(
self,
input: ai.ModelTurnInput
) -> ai.ModelTurn throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure
function

render

(
self,
input: ai.ModelTurnInput
) -> baml.http.Request throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/openai/images.bamlbytes 63036901