vercel.AiGatewayImageClient

The Vercel AI Gateway image client: POST {base_url}/image-model.

Reference version

Signature

class vercel.AiGatewayImageClient

The Vercel AI Gateway image client: POST {base_url}/image-model.

client "ai-gateway-images/bfl/flux-2-pro" in an LLM function constructs this class. The gateway fronts many image providers behind one endpoint; the model id — including its provider prefix — rides in the ai-model-id header, not in the body.

function DrawLamp(subject: string) -> image {
    client "ai-gateway-images/bfl/flux-2-pro"
    prompt `A studio photograph of ${subject}.`
}

Image inputs ARE supported: an image prompt part becomes a files[] entry, which is how the endpoint does editing and variations —

function Restyle(source: image) -> image {
    client "ai-gateway-images/openai/gpt-image-1"
    prompt `Redraw ${source} in watercolor.`
}

Audio/video/pdf inputs have no representation and are rejected, as is tool calling. (mask, the other editing input, has no first-class field yet; pass it through request_body as {"mask": {"type": "file", "mediaType": …, "data": …}}.)

Source:<builtin>/vercel/images.bamlbytes 11035618

Fields

model

string

api_key

ai.Credential | null

base_url

ai.Credential | null

n

int | null

size

string | null

aspect_ratio

string | null

seed

int | 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 = …,
aspect_ratio: string | null = …,
seed: int | null = …,
request_body: baml.json.json | null = …,
headers: map<string, string> | null = …,
query_params: map<string, string> | null = …,
capture_wire: bool = …
) -> vercel.AiGatewayImageClient

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 gateway's conventional variable. (sys_llm had no env default here and required api_key: env.AI_GATEWAY_API_KEY in every client declaration.) 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 gateway default.

Implementations

ai.Client for vercel.AiGatewayImageClient

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>/vercel/images.bamlbytes 48155428