Skip to content
API reference

darkroom

Import
import * as api from "@fungi.computer/darkroom";
Kind Export Description
class MediaSettingsError Invalid generation settings or unsupported model parameters.
type alias ImageParams Dimensions and optional settings used by the deterministic image quote.
type alias ImageReference Reference-image dimensions used to estimate provider work.
type alias MediaReference A reference file selected by the host, with its destination identity and path.
type alias ImageFormat Supported still-image encodings.
type alias ImageMimeType MIME type corresponding to a supported image encoding.
type alias MediaOutputFormat A saved generation: an image, or an MP4 from a video model.
type alias MediaReferenceBytes Decoded reference bytes and the dimensions sent to the provider.
type alias MediaGenerationSettings Normalized model settings, including bounded host-selected references.
type alias MediaProvider One Media provider call: validated settings and reference bytes in, output bytes out. Hosts may bind it to Workers AI or their own transport.
type alias FittedReferenceImage A decoded reference image, scaled within MAX_REFERENCE_DIMENSION.
type alias ReferenceImageFitter Decode one reference image and scale it within Media’s dimension bound.
type alias ImageViewFitter Decode one image and re-encode it for a model to look at: scaled within maxDimension on the long edge (bounded by viewDimensionSchema) as a lossy JPEG, so a viewer can step the dimension down to meet a byte budget.
type alias MediaGenerationSettingsInput Caller settings before model defaults and refinements are applied.
type alias MediaGenerationSelection Generation settings with reference paths resolved by an admitting host.
type alias MediaVideoReference One path-only video reference.
type alias MediaVideoSelectionInput Caller video selection before defaults and model-specific refinements.
type alias MediaVideoSelection Normalized path-only video settings, ready for host-authorized reference hydration.
type alias MediaReferenceReader Host-authorized reader for decoded reference images.
type alias MediaJsonBody Provider JSON image input for models without multipart references.
type alias MediaProviderPayload A model-specific JSON body or multipart form ready for transport.
type alias MediaProviderImageEntry One image in a provider envelope, encoded inline or available at a URL.
type alias MediaProviderOutput Parsed provider representation before conversion to bounded image bytes.
type alias MediaProviderWire Supported raw provider representations, decoded by mediaProviderWireSchema.
type alias MediaAiResult Native Workers AI output or an already decoded provider representation.
type alias MediaProviderOutputOptions Host-supplied URL fetching and maximum output bytes for normalization.
type alias MediaImageOutput Normalized bytes and their supported still-image encoding.
type alias MediaVideoQuoteSettings Authority-free video quote settings; hydrated host settings are structurally compatible.
type alias MediaModelTier A model selection tier, independent of billing price.
type alias MediaVideoModelId Verified video model identifier.
type alias MediaVideoResolution A video resolution selector.
type alias MediaVideoAspectRatio A video aspect selector.
type alias MediaVideoReferenceRole The role of a selected reference image in a video request.
type alias MediaVideoFormat One immutable nominal video format.
type alias MediaVideoModel Immutable video capability and price metadata.
type alias MediaModelInput Model-specific dimensions, steps, transport and reference limits.
type alias MediaModel One immutable provider catalog entry.
constant mediaFailureStageSchema Public diagnostic labels only; never provider messages or request data.
constant MIN_VIEW_DIMENSION The long-edge bounds a viewer may ask for when fitting an image to look at.
constant MAX_VIEW_DIMENSION Maximum long-edge size accepted by an image viewer, in pixels.
constant viewDimensionSchema Decode a viewer long-edge size within the supported pixel bounds.
constant MAX_REFERENCE_COUNT Maximum reference files in one generation request.
constant MAX_REFERENCE_DIMENSION Maximum reference width and height sent to inference, in pixels.
constant MAX_REFERENCE_BYTES Maximum decoded bytes per reference image.
constant MAX_OUTPUT_BYTES Maximum retained still-image output bytes.
constant mediaGenerationSettingsSchema Structural wire grammar for one Media generation request.
constant mediaGenerationSelectionSchema App selections contain paths; the host supplies the admitted Computer.
constant mediaVideoReferenceSchema Path-only video reference; the host supplies authority and reads its bytes.
constant mediaVideoSelectionSchema Neutral video selection; model-specific combinations are checked by validateMediaVideoSelection.
constant mediaProviderWireSchema Decode the Workers AI binding’s raw output at the provider boundary.
constant mediaRequestedImageFormatSchema An explicitly requested image encoding; video is outside this contract.
constant mediaModelTierSchema Agent-facing selection tier: cheap/fast draft work, the balanced default, premium for art the user will see, and max for the most expensive models. One value per model; never a price.
constant mediaModelInputSchema Media’s provider catalog: Workers AI images plus gateway image and video models.
constant mediaVideoModelIdSchema Verified Unified AI video identifiers; no inferred family aliases.
constant mediaVideoResolutionSchema Provider resolution selectors, refined against the selected catalog entry.
constant mediaVideoAspectRatioSchema Documented video aspect selectors, refined per model.
constant mediaVideoReferenceRoleSchema Explicit reference meaning; frame mode and reference mode are exclusive.
constant mediaVideoFormatSchema One nominal size used to select provider resolution and aspect.
constant mediaVideoSchema Verified video parameters and provider costs, checked 2026-10-11.
constant MAX_MEDIA_PROMPT_LENGTH Structural ceiling for any prompt on the wire. Each model’s own maxPromptLength is the real bound; no model may exceed this ceiling.
constant mediaModelSchema Public wire grammar for a catalog entry returned by the Media owner.
constant mediaModels The immutable image and video model catalog.
constant USD_PER_1K_NEURONS Published Workers AI image rate: $0.011 per 1,000 neurons.
function estimateImageNeurons() Estimate Workers AI neurons from a validated image request.
function estimateImageMilliunits() Quote the same estimate in milliunits (1 cent = 1,000 milliunits).
function validateMediaGenerationSettings() Validate caller settings and apply retained model defaults.
function validateMediaGenerationSelection() Validate path-only selections without inventing a Computer identity.
function validateMediaVideoSelection() Validate supported model/size/duration/reference combinations before authority or billing admission.
function resolveMediaReferences() Resolve only provider-accepted references through the caller’s reader.
function buildProviderInput() Build the exact JSON or multipart payload required by a retained model.
function parseMediaProviderOutput() Parse the provider wire envelope before normalization.
function readResponseBytes() Read a successful provider response within an explicit byte bound, closing its reader.
function normalizeMediaProviderOutput() Normalize all retained provider envelopes into bounded image bytes.
function estimateVideoMilliunits() Provider video cost from the sole catalog, in milliunits (1 cent = 1,000). Video-input references are unsupported.
function listMediaModels() List all image and video models in catalog order.
function getMediaModel() Find a model by provider identifier, returning undefined when it is absent.
function neuronsToMilliunits() Convert a neuron estimate to milliunits, rounding up to avoid underquoting.

Invalid generation settings or unsupported model parameters.

  • Error
Signature
new MediaSettingsError(message): MediaSettingsError;
Parameter Type
message string

MediaSettingsError

Signature
Error.constructor;

ImageParamstype alias

Section titled “ImageParams”
Signature
type ImageParams = object;

Dimensions and optional settings used by the deterministic image quote.

Signature
readonly height: number;

Output height in pixels.

Signature
readonly optional references?: readonly ImageReference[];

Reference dimensions counted in the quote.

Signature
readonly optional steps?: number;

Inference steps, using catalog defaults when omitted.

Signature
readonly width: number;

Output width in pixels.


ImageReferencetype alias

Section titled “ImageReference”
Signature
type ImageReference = object;

Reference-image dimensions used to estimate provider work.

Signature
readonly height: number;

Reference height in pixels.

Signature
readonly width: number;

Reference width in pixels.


MediaReferencetype alias

Section titled “MediaReference”
Signature
type MediaReference = Readonly<{
computerId: string;
path: string;
role?: MediaVideoReferenceRole;
}>;

A reference file selected by the host, with its destination identity and path.


ImageFormattype alias

Section titled “ImageFormat”
Signature
type ImageFormat = "png" | "jpeg" | "gif" | "webp";

Supported still-image encodings.


ImageMimeTypetype alias

Section titled “ImageMimeType”
Signature
type ImageMimeType = `image/${ImageFormat}`;

MIME type corresponding to a supported image encoding.


MediaOutputFormattype alias

Section titled “MediaOutputFormat”
Signature
type MediaOutputFormat = ImageFormat | "mp4";

A saved generation: an image, or an MP4 from a video model.


MediaReferenceBytestype alias

Section titled “MediaReferenceBytes”
Signature
type MediaReferenceBytes = Readonly<{
bytes: Uint8Array;
format: ImageFormat;
width: number;
height: number;
filename?: string;
}>;

Decoded reference bytes and the dimensions sent to the provider.


MediaGenerationSettingstype alias

Section titled “MediaGenerationSettings”
Signature
type MediaGenerationSettings = Readonly<{
model: string;
prompt: string;
width: number;
height: number;
steps?: number;
durationSeconds?: number;
resolution?: MediaVideoResolution;
aspectRatio?: MediaVideoAspectRatio;
generateAudio?: boolean;
references?: readonly MediaReference[];
}>;

Normalized model settings, including bounded host-selected references.


MediaProvidertype alias

Section titled “MediaProvider”
Signature
type MediaProvider = (
settings,
references,
signal?,
outputFormat?,
) => Promise<
Readonly<{
bytes: Uint8Array;
format: string;
}>
>;

One Media provider call: validated settings and reference bytes in, output bytes out. Hosts may bind it to Workers AI or their own transport.

Parameter Type
settings MediaGenerationSettings
references readonly MediaReferenceBytes[]
signal? AbortSignal
outputFormat? "png" | "jpeg" | "webp"

Promise<Readonly<{ bytes: Uint8Array; format: string; }>>


FittedReferenceImagetype alias

Section titled “FittedReferenceImage”
Signature
type FittedReferenceImage = Omit<MediaReferenceBytes, "filename">;

A decoded reference image, scaled within MAX_REFERENCE_DIMENSION.


ReferenceImageFittertype alias

Section titled “ReferenceImageFitter”
Signature
type ReferenceImageFitter = (bytes) => Promise<FittedReferenceImage>;

Decode one reference image and scale it within Media’s dimension bound.

Parameter Type
bytes Uint8Array

Promise<FittedReferenceImage>


ImageViewFittertype alias

Section titled “ImageViewFitter”
Signature
type ImageViewFitter = (bytes, maxDimension) => Promise<FittedReferenceImage>;

Decode one image and re-encode it for a model to look at: scaled within maxDimension on the long edge (bounded by viewDimensionSchema) as a lossy JPEG, so a viewer can step the dimension down to meet a byte budget.

Parameter Type
bytes Uint8Array
maxDimension number

Promise<FittedReferenceImage>


MediaGenerationSettingsInputtype alias

Section titled “MediaGenerationSettingsInput”
Signature
type MediaGenerationSettingsInput = z.input<
typeof mediaGenerationSettingsSchema
>;

Caller settings before model defaults and refinements are applied.


MediaGenerationSelectiontype alias

Section titled “MediaGenerationSelection”
Signature
type MediaGenerationSelection = z.output<typeof mediaGenerationSelectionSchema>;

Generation settings with reference paths resolved by an admitting host.


MediaVideoReferencetype alias

Section titled “MediaVideoReference”
Signature
type MediaVideoReference = z.output<typeof mediaVideoReferenceSchema>;

One path-only video reference.


MediaVideoSelectionInputtype alias

Section titled “MediaVideoSelectionInput”
Signature
type MediaVideoSelectionInput = z.input<typeof mediaVideoSelectionSchema>;

Caller video selection before defaults and model-specific refinements.


MediaVideoSelectiontype alias

Section titled “MediaVideoSelection”
Signature
type MediaVideoSelection = Readonly<{
model: MediaVideoModelId;
prompt: string;
width: number;
height: number;
resolution: MediaVideoResolution;
aspectRatio: MediaVideoAspectRatio;
durationSeconds: number;
generateAudio?: boolean;
references?: readonly Readonly<MediaVideoReference>[];
}>;

Normalized path-only video settings, ready for host-authorized reference hydration.


MediaReferenceReadertype alias

Section titled “MediaReferenceReader”
Signature
type MediaReferenceReader = Readonly<{
read: (reference) => Promise<MediaReferenceBytes>;
}>;

Host-authorized reader for decoded reference images.


MediaJsonBodytype alias

Section titled “MediaJsonBody”
Signature
type MediaJsonBody = Readonly<{
prompt: string;
width?: number;
height?: number;
steps?: number;
num_steps?: number;
}>;

Provider JSON image input for models without multipart references.


MediaProviderPayloadtype alias

Section titled “MediaProviderPayload”
Signature
type MediaProviderPayload =
| Readonly<{
transport: "json";
body: MediaJsonBody;
}>
| Readonly<{
transport: "multipart";
body: FormData;
}>;

A model-specific JSON body or multipart form ready for transport.


MediaProviderImageEntrytype alias

Section titled “MediaProviderImageEntry”
Signature
type MediaProviderImageEntry = Readonly<{
base64?: string;
data?: string;
url?: string;
}>;

One image in a provider envelope, encoded inline or available at a URL.


MediaProviderOutputtype alias

Section titled “MediaProviderOutput”
Signature
type MediaProviderOutput =
| Readonly<{
kind: "bytes";
bytes: Uint8Array;
}>
| Readonly<{
kind: "response";
response: Response;
}>
| Readonly<{
kind: "encoded";
encoded: string;
}>
| Readonly<{
kind: "entries";
entries: readonly MediaProviderImageEntry[];
}>;

Parsed provider representation before conversion to bounded image bytes.


MediaProviderWiretype alias

Section titled “MediaProviderWire”
Signature
type MediaProviderWire = z.output<typeof mediaProviderWireSchema>;

Supported raw provider representations, decoded by mediaProviderWireSchema.


MediaAiResulttype alias

Section titled “MediaAiResult”
Signature
type MediaAiResult = Awaited<ReturnType<Ai["run"]>> | MediaProviderWire;

Native Workers AI output or an already decoded provider representation.


MediaProviderOutputOptionstype alias

Section titled “MediaProviderOutputOptions”
Signature
type MediaProviderOutputOptions = Readonly<{
fetchUrl?: (url) => Promise<Response>;
maxBytes?: number;
}>;

Host-supplied URL fetching and maximum output bytes for normalization.


MediaImageOutputtype alias

Section titled “MediaImageOutput”
Signature
type MediaImageOutput = Readonly<{
bytes: Uint8Array;
format: ImageFormat;
}>;

Normalized bytes and their supported still-image encoding.


MediaVideoQuoteSettingstype alias

Section titled “MediaVideoQuoteSettings”
Signature
type MediaVideoQuoteSettings = ReturnType<
typeof validateMediaGenerationSelection
>;

Authority-free video quote settings; hydrated host settings are structurally compatible.


MediaModelTiertype alias

Section titled “MediaModelTier”
Signature
type MediaModelTier = z.output<typeof mediaModelTierSchema>;

A model selection tier, independent of billing price.


MediaVideoModelIdtype alias

Section titled “MediaVideoModelId”
Signature
type MediaVideoModelId = z.output<typeof mediaVideoModelIdSchema>;

Verified video model identifier.


MediaVideoResolutiontype alias

Section titled “MediaVideoResolution”
Signature
type MediaVideoResolution = z.output<typeof mediaVideoResolutionSchema>;

A video resolution selector.


MediaVideoAspectRatiotype alias

Section titled “MediaVideoAspectRatio”
Signature
type MediaVideoAspectRatio = z.output<typeof mediaVideoAspectRatioSchema>;

A video aspect selector.


MediaVideoReferenceRoletype alias

Section titled “MediaVideoReferenceRole”
Signature
type MediaVideoReferenceRole = z.output<typeof mediaVideoReferenceRoleSchema>;

The role of a selected reference image in a video request.


MediaVideoFormattype alias

Section titled “MediaVideoFormat”
Signature
type MediaVideoFormat = z.output<typeof mediaVideoFormatSchema>;

One immutable nominal video format.


MediaVideoModeltype alias

Section titled “MediaVideoModel”
Signature
type MediaVideoModel = z.output<typeof mediaVideoSchema>;

Immutable video capability and price metadata.


MediaModelInputtype alias

Section titled “MediaModelInput”
Signature
type MediaModelInput = z.output<typeof mediaModelInputSchema>;

Model-specific dimensions, steps, transport and reference limits.


MediaModeltype alias

Section titled “MediaModel”
Signature
type MediaModel = z.output<typeof mediaModelSchema>;

One immutable provider catalog entry.

mediaFailureStageSchemaconstant

Section titled “mediaFailureStageSchema”
Signature
const mediaFailureStageSchema: ZodEnum<{
admission: "admission";
generation-authorization: "generation-authorization";
settings: "settings";
estimate: "estimate";
billing: "billing";
operation: "operation";
provider: "provider";
normalization: "normalization";
artifact: "artifact";
destination-authorization: "destination-authorization";
destination-write: "destination-write";
}>;

Public diagnostic labels only; never provider messages or request data.


MIN_VIEW_DIMENSIONconstant

Section titled “MIN_VIEW_DIMENSION”
Signature
const MIN_VIEW_DIMENSION: 256 = 256;

The long-edge bounds a viewer may ask for when fitting an image to look at.


MAX_VIEW_DIMENSIONconstant

Section titled “MAX_VIEW_DIMENSION”
Signature
const MAX_VIEW_DIMENSION: 512 = 512;

Maximum long-edge size accepted by an image viewer, in pixels.


viewDimensionSchemaconstant

Section titled “viewDimensionSchema”
Signature
const viewDimensionSchema: ZodLazy<ZodNumber>;

Decode a viewer long-edge size within the supported pixel bounds.


MAX_REFERENCE_COUNTconstant

Section titled “MAX_REFERENCE_COUNT”
Signature
const MAX_REFERENCE_COUNT: 4 = 4;

Maximum reference files in one generation request.


MAX_REFERENCE_DIMENSIONconstant

Section titled “MAX_REFERENCE_DIMENSION”
Signature
const MAX_REFERENCE_DIMENSION: 512 = 512;

Maximum reference width and height sent to inference, in pixels.


MAX_REFERENCE_BYTESconstant

Section titled “MAX_REFERENCE_BYTES”
Signature
const MAX_REFERENCE_BYTES: number;

Maximum decoded bytes per reference image.


MAX_OUTPUT_BYTESconstant

Section titled “MAX_OUTPUT_BYTES”
Signature
const MAX_OUTPUT_BYTES: number;

Maximum retained still-image output bytes.


mediaGenerationSettingsSchemaconstant

Section titled “mediaGenerationSettingsSchema”
Signature
const mediaGenerationSettingsSchema: ZodObject<
{
model: ZodString;
prompt: ZodString;
width: ZodNumber;
height: ZodNumber;
steps: ZodOptional<ZodNumber>;
durationSeconds: ZodOptional<ZodNumber>;
resolution: ZodOptional<
ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>
>;
aspectRatio: ZodOptional<
ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>
>;
generateAudio: ZodOptional<ZodBoolean>;
references: ZodOptional<
ZodArray<
ZodObject<
{
computerId: ZodString;
path: ZodString;
role: ZodOptional<
ZodEnum<{
first: "first-frame";
last: "last-frame";
reference: "reference";
}>
>;
},
$strict
>
>
>;
},
$strict
>;

Structural wire grammar for one Media generation request.


mediaGenerationSelectionSchemaconstant

Section titled “mediaGenerationSelectionSchema”
Signature
const mediaGenerationSelectionSchema: ZodObject<
{
model: ZodString;
prompt: ZodString;
width: ZodNumber;
height: ZodNumber;
steps: ZodOptional<ZodNumber>;
durationSeconds: ZodOptional<ZodNumber>;
resolution: ZodOptional<
ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>
>;
aspectRatio: ZodOptional<
ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>
>;
generateAudio: ZodOptional<ZodBoolean>;
references: ZodOptional<
ZodArray<
ZodObject<
{
path: ZodString;
role: ZodOptional<
ZodEnum<{
first: "first-frame";
last: "last-frame";
reference: "reference";
}>
>;
},
$strict
>
>
>;
},
$strict
>;

App selections contain paths; the host supplies the admitted Computer.


mediaVideoReferenceSchemaconstant

Section titled “mediaVideoReferenceSchema”
Signature
const mediaVideoReferenceSchema: ZodLazy<
ZodObject<
{
path: ZodString;
role: ZodEnum<{
first: "first-frame";
last: "last-frame";
reference: "reference";
}>;
},
$strict
>
>;

Path-only video reference; the host supplies authority and reads its bytes.


mediaVideoSelectionSchemaconstant

Section titled “mediaVideoSelectionSchema”
Signature
const mediaVideoSelectionSchema: ZodLazy<
ZodObject<
{
model: ZodEnum<{
seedance: "bytedance/seedance-2.0";
seedanceFast: "bytedance/seedance-2.0-fast";
seedanceMini: "bytedance/seedance-2.0-mini";
veo: "google/veo-3.1";
veoFast: "google/veo-3.1-fast";
minimaxH3Max: "minimax/h3-max";
}>;
prompt: ZodString;
resolution: ZodOptional<
ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>
>;
aspectRatio: ZodOptional<
ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>
>;
durationSeconds: ZodOptional<ZodNumber>;
generateAudio: ZodOptional<ZodBoolean>;
references: ZodOptional<
ZodArray<
ZodLazy<
ZodObject<
{
path: ZodString;
role: ZodEnum<{
first: "first-frame";
last: "last-frame";
reference: "reference";
}>;
},
$strict
>
>
>
>;
},
$strict
>
>;

Neutral video selection; model-specific combinations are checked by validateMediaVideoSelection.


mediaProviderWireSchemaconstant

Section titled “mediaProviderWireSchema”
Signature
const mediaProviderWireSchema: ZodLazy<ZodUnion<readonly [ZodLazy<ZodUnion<readonly [ZodObject<{
image: ZodString;
}, $strip>, ZodObject<{
image: ZodArray<ZodLazy<ZodObject<..., ...>>>;
}, $strip>, ZodObject<{
images: ZodArray<ZodLazy<ZodObject<..., ...>>>;
}, $strip>]>>, ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, ZodCustom<Response, Response>, ZodCustom<ReadableStream<Uint8Array<ArrayBufferLike>>, ReadableStream<Uint8Array<ArrayBufferLike>>>]>>;

Decode the Workers AI binding’s raw output at the provider boundary.


mediaRequestedImageFormatSchemaconstant

Section titled “mediaRequestedImageFormatSchema”
Signature
const mediaRequestedImageFormatSchema: ZodEnum<{
png: "png";
jpeg: "jpeg";
webp: "webp";
}>;

An explicitly requested image encoding; video is outside this contract.


mediaModelTierSchemaconstant

Section titled “mediaModelTierSchema”
Signature
const mediaModelTierSchema: ZodEnum<{
draft: "draft";
balanced: "balanced";
premium: "premium";
max: "max";
}>;

Agent-facing selection tier: cheap/fast draft work, the balanced default, premium for art the user will see, and max for the most expensive models. One value per model; never a price.


mediaModelInputSchemaconstant

Section titled “mediaModelInputSchema”
Signature
const mediaModelInputSchema: ZodLazy<
ZodReadonly<
ZodObject<
{
transport: ZodEnum<{
json: "json";
multipart: "multipart";
}>;
dimensions: ZodEnum<{
none: "none";
own: "own";
}>;
maxDimension: ZodNullable<ZodNumber>;
defaultWidth: ZodNumber;
defaultHeight: ZodNumber;
steps: ZodEnum<{
steps: "steps";
num_steps: "num_steps";
fixed: "fixed";
}>;
maxSteps: ZodNullable<ZodNumber>;
defaultSteps: ZodNullable<ZodNumber>;
referenceField: ZodNullable<ZodString>;
maxReferences: ZodNumber;
},
$strict
>
>
>;

Media’s provider catalog: Workers AI images plus gateway image and video models.


mediaVideoModelIdSchemaconstant

Section titled “mediaVideoModelIdSchema”
Signature
const mediaVideoModelIdSchema: ZodEnum<{
seedance: "bytedance/seedance-2.0";
seedanceFast: "bytedance/seedance-2.0-fast";
seedanceMini: "bytedance/seedance-2.0-mini";
veo: "google/veo-3.1";
veoFast: "google/veo-3.1-fast";
minimaxH3Max: "minimax/h3-max";
}>;

Verified Unified AI video identifiers; no inferred family aliases.


mediaVideoResolutionSchemaconstant

Section titled “mediaVideoResolutionSchema”
Signature
const mediaVideoResolutionSchema: ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>;

Provider resolution selectors, refined against the selected catalog entry.


mediaVideoAspectRatioSchemaconstant

Section titled “mediaVideoAspectRatioSchema”
Signature
const mediaVideoAspectRatioSchema: ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>;

Documented video aspect selectors, refined per model.


mediaVideoReferenceRoleSchemaconstant

Section titled “mediaVideoReferenceRoleSchema”
Signature
const mediaVideoReferenceRoleSchema: ZodEnum<{
first: "first-frame";
last: "last-frame";
reference: "reference";
}>;

Explicit reference meaning; frame mode and reference mode are exclusive.


mediaVideoFormatSchemaconstant

Section titled “mediaVideoFormatSchema”
Signature
const mediaVideoFormatSchema: ZodLazy<
ZodReadonly<
ZodObject<
{
resolution: ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>;
aspectRatio: ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>;
width: ZodNumber;
height: ZodNumber;
},
$strict
>
>
>;

One nominal size used to select provider resolution and aspect.


mediaVideoSchemaconstant

Section titled “mediaVideoSchema”
Signature
const mediaVideoSchema: ZodLazy<ZodReadonly<ZodObject<{
minSeconds: ZodNumber;
maxSeconds: ZodNumber;
defaultSeconds: ZodNumber;
durations: ZodReadonly<ZodArray<ZodNumber>>;
provider: ZodEnum<{
seedance: "seedance";
veo: "veo";
minimax: "minimax";
}>;
formats: ZodReadonly<ZodArray<ZodLazy<ZodReadonly<ZodObject<{
resolution: ZodEnum<...>;
aspectRatio: ZodEnum<...>;
width: ZodNumber;
height: ZodNumber;
}, $strict>>>>>;
defaultResolution: ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>;
defaultAspectRatio: ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>;
defaultGenerateAudio: ZodNullable<ZodBoolean>;
referenceRoles: ZodReadonly<ZodArray<ZodEnum<{
first: "first-frame";
last: "last-frame";
reference: "reference";
}>>>;
maxReferenceImages: ZodNumber;
referenceResolutions: ZodReadonly<ZodArray<ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>>>;
prices: ZodReadonly<ZodArray<ZodReadonly<ZodObject<{
resolution: ZodEnum<{
p480: ...;
p720: ...;
p768: ...;
p1080: ...;
p4k: ...;
}>;
silentMilliunitsPerSecond: ZodNumber;
audioMilliunitsPerSecond: ZodNumber;
}, $strict>>>>;
}, $strict>>>;

Verified video parameters and provider costs, checked 2026-10-11.


MAX_MEDIA_PROMPT_LENGTHconstant

Section titled “MAX_MEDIA_PROMPT_LENGTH”
Signature
const MAX_MEDIA_PROMPT_LENGTH: 32000 = 32_000;

Structural ceiling for any prompt on the wire. Each model’s own maxPromptLength is the real bound; no model may exceed this ceiling.


mediaModelSchemaconstant

Section titled “mediaModelSchema”
Signature
const mediaModelSchema: ZodReadonly<ZodObject<{
id: ZodString;
label: ZodString;
kind: ZodEnum<{
image: "image";
video: "video";
}>;
tier: ZodEnum<{
draft: "draft";
balanced: "balanced";
premium: "premium";
max: "max";
}>;
outputFormats: ZodReadonly<ZodArray<ZodEnum<{
png: "png";
jpeg: "jpeg";
webp: "webp";
}>>>;
maxPromptLength: ZodNumber;
input: ZodLazy<ZodReadonly<ZodObject<{
transport: ZodEnum<{
json: "json";
multipart: "multipart";
}>;
dimensions: ZodEnum<{
none: "none";
own: "own";
}>;
maxDimension: ZodNullable<ZodNumber>;
defaultWidth: ZodNumber;
defaultHeight: ZodNumber;
steps: ZodEnum<{
steps: "steps";
num_steps: "num_steps";
fixed: "fixed";
}>;
maxSteps: ZodNullable<ZodNumber>;
defaultSteps: ZodNullable<ZodNumber>;
referenceField: ZodNullable<ZodString>;
maxReferences: ZodNumber;
}, $strict>>>;
sizes: ZodNullable<ZodReadonly<ZodArray<ZodString>>>;
video: ZodNullable<ZodLazy<ZodReadonly<ZodObject<{
minSeconds: ZodNumber;
maxSeconds: ZodNumber;
defaultSeconds: ZodNumber;
durations: ZodReadonly<ZodArray<ZodNumber>>;
provider: ZodEnum<{
seedance: "seedance";
veo: "veo";
minimax: "minimax";
}>;
formats: ZodReadonly<ZodArray<ZodLazy<...>>>;
defaultResolution: ZodEnum<{
p480: "480p";
p720: "720p";
p768: "768p";
p1080: "1080p";
p4k: "4k";
}>;
defaultAspectRatio: ZodEnum<{
wide: "16:9";
landscape: "4:3";
square: "1:1";
portrait: "3:4";
tall: "9:16";
ultrawide: "21:9";
ultratall: "9:21";
}>;
defaultGenerateAudio: ZodNullable<ZodBoolean>;
referenceRoles: ZodReadonly<ZodArray<ZodEnum<...>>>;
maxReferenceImages: ZodNumber;
referenceResolutions: ZodReadonly<ZodArray<ZodEnum<...>>>;
prices: ZodReadonly<ZodArray<ZodReadonly<...>>>;
}, $strict>>>>;
}, $strict>>;

Public wire grammar for a catalog entry returned by the Media owner.


mediaModelsconstant

Section titled “mediaModels”
Signature
const mediaModels: readonly MediaModel[] = models;

The immutable image and video model catalog.


USD_PER_1K_NEURONSconstant

Section titled “USD_PER_1K_NEURONS”
Signature
const USD_PER_1K_NEURONS: 0.011 = 0.011;

Published Workers AI image rate: $0.011 per 1,000 neurons.

estimateImageNeurons()function

Section titled “estimateImageNeurons()”
Signature
function estimateImageNeurons(modelId, params): number;

Estimate Workers AI neurons from a validated image request.

Parameter Type
modelId string
params ImageParams

number


estimateImageMilliunits()function

Section titled “estimateImageMilliunits()”
Signature
function estimateImageMilliunits(modelId, params): number;

Quote the same estimate in milliunits (1 cent = 1,000 milliunits).

Parameter Type
modelId string
params ImageParams

number


validateMediaGenerationSettings()function

Section titled “validateMediaGenerationSettings()”
Signature
function validateMediaGenerationSettings(raw): MediaGenerationSettings;

Validate caller settings and apply retained model defaults.

Parameter Type Description
raw { model: string; prompt: string; width: number; height: number; steps?: number; durationSeconds?: number; resolution?: "480p" | "720p" | "768p" | "1080p" | "4k"; aspectRatio?: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; generateAudio?: boolean; references?: object[]; } -
raw.model string Provider catalog model identifier.
raw.prompt string Generation prompt; each model’s maxPromptLength is enforced on top of this ceiling.
raw.width number Requested image width or nominal video selector, not decoded MP4 dimensions.
raw.height number Requested image height or nominal video selector, not decoded MP4 dimensions.
raw.steps? number Model-specific inference step count.
raw.durationSeconds? number Requested video length in whole seconds.
raw.resolution? "480p" | "720p" | "768p" | "1080p" | "4k" Video resolution; must match the nominal width/height selector.
raw.aspectRatio? "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21" Video aspect; must match the nominal width/height selector.
raw.generateAudio? boolean Video audio selection.
raw.references? object[] Host-authorized reference images.

MediaGenerationSettings


validateMediaGenerationSelection()function

Section titled “validateMediaGenerationSelection()”
Signature
function validateMediaGenerationSelection(
raw,
): Readonly<Omit<MediaGenerationSettings, "references"> & object>;

Validate path-only selections without inventing a Computer identity.

Parameter Type Description
raw { model: string; prompt: string; width: number; height: number; steps?: number; durationSeconds?: number; resolution?: "480p" | "720p" | "768p" | "1080p" | "4k"; aspectRatio?: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; generateAudio?: boolean; references?: object[]; } -
raw.model string Provider catalog model identifier.
raw.prompt string Generation prompt; each model’s maxPromptLength is enforced on top of this ceiling.
raw.width number Requested image width or nominal video selector, not decoded MP4 dimensions.
raw.height number Requested image height or nominal video selector, not decoded MP4 dimensions.
raw.steps? number Model-specific inference step count.
raw.durationSeconds? number Requested video length in whole seconds.
raw.resolution? "480p" | "720p" | "768p" | "1080p" | "4k" Video resolution; must match the nominal width/height selector.
raw.aspectRatio? "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21" Video aspect; must match the nominal width/height selector.
raw.generateAudio? boolean Video audio selection.
raw.references? object[] Host-authorized reference images.

Readonly<Omit<MediaGenerationSettings, "references"> & object>


validateMediaVideoSelection()function

Section titled “validateMediaVideoSelection()”
Signature
function validateMediaVideoSelection(raw): MediaVideoSelection;

Validate supported model/size/duration/reference combinations before authority or billing admission.

Parameter Type Description
raw { model: | "bytedance/seedance-2.0" | "bytedance/seedance-2.0-fast" | "bytedance/seedance-2.0-mini" | "google/veo-3.1" | "google/veo-3.1-fast" | "minimax/h3-max"; prompt: string; resolution?: "480p" | "720p" | "768p" | "1080p" | "4k"; aspectRatio?: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; durationSeconds?: number; generateAudio?: boolean; references?: object[]; } -
raw.model | "bytedance/seedance-2.0" | "bytedance/seedance-2.0-fast" | "bytedance/seedance-2.0-mini" | "google/veo-3.1" | "google/veo-3.1-fast" | "minimax/h3-max" Verified catalog model identifier.
raw.prompt string Trimmed prompt; the selected model’s maxPromptLength is enforced on top of this ceiling.
raw.resolution? "480p" | "720p" | "768p" | "1080p" | "4k" Model-specific resolution, default 720p.
raw.aspectRatio? "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21" Model-specific aspect, default 16:9.
raw.durationSeconds? number Whole seconds; Seedance 4–12, Veo exactly 4/6/8, MiniMax H3 Max 5–15.
raw.generateAudio? boolean Veo defaults true; Seedance omits the provider option when unset; MiniMax H3 Max has no audio field and refuses an explicit choice.
raw.references? object[] Up to four references, with provider-specific roles and mode limits.

MediaVideoSelection


resolveMediaReferences()function

Section titled “resolveMediaReferences()”
Signature
function resolveMediaReferences(
settings,
reader,
): Promise<
readonly Readonly<{
bytes: Uint8Array;
format: ImageFormat;
width: number;
height: number;
filename?: string;
}>[]
>;

Resolve only provider-accepted references through the caller’s reader.

Parameter Type
settings MediaGenerationSettings
reader MediaReferenceReader

Promise<readonly Readonly<{ bytes: Uint8Array; format: ImageFormat; width: number; height: number; filename?: string; }>[]>


buildProviderInput()function

Section titled “buildProviderInput()”
Signature
function buildProviderInput(settings, references?): MediaProviderPayload;

Build the exact JSON or multipart payload required by a retained model.

Parameter Type Default value
settings MediaGenerationSettings undefined
references readonly Readonly<{ bytes: Uint8Array; format: ImageFormat; width: number; height: number; filename?: string; }>[] []

MediaProviderPayload


parseMediaProviderOutput()function

Section titled “parseMediaProviderOutput()”
Signature
function parseMediaProviderOutput(value): MediaProviderOutput;

Parse the provider wire envelope before normalization.

Parameter Type
value | Response | Uint8Array<ArrayBuffer> | ReadableStream<Uint8Array<ArrayBufferLike>> | { image: string; } | { image: object[]; } | { images: object[]; }

MediaProviderOutput


readResponseBytes()function

Section titled “readResponseBytes()”
Signature
function readResponseBytes(
response,
maximumBytes,
): Promise<Uint8Array<ArrayBufferLike>>;

Read a successful provider response within an explicit byte bound, closing its reader.

Parameter Type
response Response
maximumBytes number

Promise<Uint8Array<ArrayBufferLike>>


normalizeMediaProviderOutput()function

Section titled “normalizeMediaProviderOutput()”
Signature
function normalizeMediaProviderOutput(
value,
options?,
): Promise<
Readonly<{
bytes: Uint8Array;
format: ImageFormat;
}>
>;

Normalize all retained provider envelopes into bounded image bytes.

Parameter Type
value | Response | Uint8Array<ArrayBuffer> | ReadableStream<Uint8Array<ArrayBufferLike>> | { image: string; } | { image: object[]; } | { images: object[]; }
options MediaProviderOutputOptions

Promise<Readonly<{ bytes: Uint8Array; format: ImageFormat; }>>


estimateVideoMilliunits()function

Section titled “estimateVideoMilliunits()”
Signature
function estimateVideoMilliunits(settings): number;

Provider video cost from the sole catalog, in milliunits (1 cent = 1,000). Video-input references are unsupported.

Parameter Type
settings MediaVideoQuoteSettings

number


listMediaModels()function

Section titled “listMediaModels()”
Signature
function listMediaModels(): readonly Readonly<{
id: string;
label: string;
kind: "image" | "video";
tier: "draft" | "balanced" | "premium" | "max";
outputFormats: readonly ("png" | "jpeg" | "webp")[];
maxPromptLength: number;
input: Readonly<{
transport: "json" | "multipart";
dimensions: "none" | "own";
maxDimension: number | null;
defaultWidth: number;
defaultHeight: number;
steps: "steps" | "num_steps" | "fixed";
maxSteps: number | null;
defaultSteps: number | null;
referenceField: string | null;
maxReferences: number;
}>;
sizes: readonly string[] | null;
video: Readonly<{
minSeconds: number;
maxSeconds: number;
defaultSeconds: number;
durations: readonly number[];
provider: "seedance" | "veo" | "minimax";
formats: readonly Readonly<{
resolution: "480p" | "720p" | "768p" | "1080p" | "4k";
aspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21";
width: number;
height: number;
}>[];
defaultResolution: "480p" | "720p" | "768p" | "1080p" | "4k";
defaultAspectRatio:
"16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21";
defaultGenerateAudio: boolean | null;
referenceRoles: readonly ("first-frame" | "last-frame" | "reference")[];
maxReferenceImages: number;
referenceResolutions: readonly (
"480p" | "720p" | "768p" | "1080p" | "4k"
)[];
prices: readonly Readonly<{
resolution: "480p" | "720p" | "768p" | "1080p" | "4k";
silentMilliunitsPerSecond: number;
audioMilliunitsPerSecond: number;
}>[];
}> | null;
}>[];

List all image and video models in catalog order.

readonly Readonly<{ id: string; label: string; kind: "image" | "video"; tier: "draft" | "balanced" | "premium" | "max"; outputFormats: readonly ("png" | "jpeg" | "webp")[]; maxPromptLength: number; input: Readonly<{ transport: "json" | "multipart"; dimensions: "none" | "own"; maxDimension: number | null; defaultWidth: number; defaultHeight: number; steps: "steps" | "num_steps" | "fixed"; maxSteps: number | null; defaultSteps: number | null; referenceField: string | null; maxReferences: number; }>; sizes: readonly string[] | null; video: | Readonly<{ minSeconds: number; maxSeconds: number; defaultSeconds: number; durations: readonly number[]; provider: "seedance" | "veo" | "minimax"; formats: readonly Readonly<{ resolution: "480p" | "720p" | "768p" | "1080p" | "4k"; aspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; width: number; height: number; }>[]; defaultResolution: "480p" | "720p" | "768p" | "1080p" | "4k"; defaultAspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; defaultGenerateAudio: boolean | null; referenceRoles: readonly ("first-frame" | "last-frame" | "reference")[]; maxReferenceImages: number; referenceResolutions: readonly ("480p" | "720p" | "768p" | "1080p" | "4k")[]; prices: readonly Readonly<{ resolution: "480p" | "720p" | "768p" | "1080p" | "4k"; silentMilliunitsPerSecond: number; audioMilliunitsPerSecond: number; }>[]; }> | null; }>[]


getMediaModel()function

Section titled “getMediaModel()”
Signature
function getMediaModel(id):
| Readonly<{
id: string;
label: string;
kind: "image" | "video";
tier: "draft" | "balanced" | "premium" | "max";
outputFormats: readonly ("png" | "jpeg" | "webp")[];
maxPromptLength: number;
input: Readonly<{
transport: "json" | "multipart";
dimensions: "none" | "own";
maxDimension: number | null;
defaultWidth: number;
defaultHeight: number;
steps: "steps" | "num_steps" | "fixed";
maxSteps: number | null;
defaultSteps: number | null;
referenceField: string | null;
maxReferences: number;
}>;
sizes: readonly string[] | null;
video: Readonly<{
minSeconds: number;
maxSeconds: number;
defaultSeconds: number;
durations: readonly number[];
provider: "seedance" | "veo" | "minimax";
formats: readonly Readonly<{
resolution: "480p" | "720p" | "768p" | "1080p" | "4k";
aspectRatio:
"16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21";
width: number;
height: number;
}>[];
defaultResolution: "480p" | "720p" | "768p" | "1080p" | "4k";
defaultAspectRatio:
"16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21";
defaultGenerateAudio: boolean | null;
referenceRoles: readonly ("first-frame" | "last-frame" | "reference")[];
maxReferenceImages: number;
referenceResolutions: readonly (
"480p" | "720p" | "768p" | "1080p" | "4k"
)[];
prices: readonly Readonly<{
resolution: "480p" | "720p" | "768p" | "1080p" | "4k";
silentMilliunitsPerSecond: number;
audioMilliunitsPerSecond: number;
}>[];
}> | null;
}>
| undefined;

Find a model by provider identifier, returning undefined when it is absent.

Parameter Type
id string

| Readonly<{ id: string; label: string; kind: "image" | "video"; tier: "draft" | "balanced" | "premium" | "max"; outputFormats: readonly ("png" | "jpeg" | "webp")[]; maxPromptLength: number; input: Readonly<{ transport: "json" | "multipart"; dimensions: "none" | "own"; maxDimension: number | null; defaultWidth: number; defaultHeight: number; steps: "steps" | "num_steps" | "fixed"; maxSteps: number | null; defaultSteps: number | null; referenceField: string | null; maxReferences: number; }>; sizes: readonly string[] | null; video: | Readonly<{ minSeconds: number; maxSeconds: number; defaultSeconds: number; durations: readonly number[]; provider: "seedance" | "veo" | "minimax"; formats: readonly Readonly<{ resolution: "480p" | "720p" | "768p" | "1080p" | "4k"; aspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; width: number; height: number; }>[]; defaultResolution: "480p" | "720p" | "768p" | "1080p" | "4k"; defaultAspectRatio: "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9" | "9:21"; defaultGenerateAudio: boolean | null; referenceRoles: readonly ("first-frame" | "last-frame" | "reference")[]; maxReferenceImages: number; referenceResolutions: readonly ("480p" | "720p" | "768p" | "1080p" | "4k")[]; prices: readonly Readonly<{ resolution: "480p" | "720p" | "768p" | "1080p" | "4k"; silentMilliunitsPerSecond: number; audioMilliunitsPerSecond: number; }>[]; }> | null; }> | undefined


neuronsToMilliunits()function

Section titled “neuronsToMilliunits()”
Signature
function neuronsToMilliunits(neurons): number;

Convert a neuron estimate to milliunits, rounding up to avoid underquoting.

Parameter Type
neurons number

number