Image and Video Model Run API: Invocation, Parameters, and Async Delivery
How to call Cloudflare Workers AI image and video models via env.AI.run or REST, pick model IDs and inputs, read varied responses, and use webhooks and AI Gateway.
This page summarizes Cloudflare documentation for running catalog image, video, and audio models from a Worker with the AI binding or from the account REST endpoint POST .../ai/run. The same logical inputs appear in both paths; what changes is transport, how long you keep the connection open, and— for some providers—whether you call the catalog or AI Gateway instead.
env.AI.run and REST ai/run: how to call a model from a Worker
Section titled “env.AI.run and REST ai/run: how to call a model from a Worker”From a Worker with an AI binding, you pass the model ID string and an object of input fields documented on that model’s page:
const response = await env.AI.run('<model-id>', { /* input fields */ });Some examples add a third argument for gateway routing—for instance Kling v3 image uses { gateway: { id: 'default' } }.
The REST equivalent for most catalog models is:
curl "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run" \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{ "model": "<model-id>", "input": { } }'Model pages (Seedream 4.5, Veo 3.1, Bria FIBO edit) show parallel Worker and cURL examples with the same fields inside input.
Model ID strings: catalog vendor/model vs @cf/ paths
Section titled “Model ID strings: catalog vendor/model vs @cf/ paths”Catalog partner models use IDs like bytedance/seedream-5-pro, google/veo-3.1-fast, or bria/fibo-generate-1.5. Workers-hosted models use the @cf/ prefix, e.g. @cf/black-forest-labs/flux-1-schnell (documented on both the @cf path and workers-ai flux-1-schnell pages). The ID in env.AI.run('…') must match the string at the top of that model’s documentation.
Prompt fields and modality: what to pass in input
Section titled “Prompt fields and modality: what to pass in input”Most text-to-image and text-to-video models expect prompt. Google Gemini Omni video models (gemini-omni-flash, gemini-omni-1.1-flash) use text instead—using prompt there is a common integration mistake.
Reference and edit flows use different names even within one vendor family:
| Pattern | Example models | Parameter |
|---|---|---|
| Single reference URL | Seedream 5 Pro | image |
| One or more reference URLs | Seedream 4.5, Seedream 5 Lite | image_input |
| Image-to-video | Wan 2.7 I2V, Alibaba HH1 I2V | image + prompt |
| Multi-image video | HH1.1 R2V, MiniMax H3 | images[] or content[] with image_url roles |
| Masked edit | Bria FIBO Edit 1.5 | instruction, images[], optional mask |
| Video upscale / enhance | Topaz fast upscale | video_uri, frame metadata—not a text prompt |
Aspect ratio, size, resolution, and duration
Section titled “Aspect ratio, size, resolution, and duration”Vendors name sizing differently. Copy values exactly from the model page:
| Concept | Typical parameter names | Examples in cluster |
|---|---|---|
| Aspect | aspect_ratio, ratio |
Seedream '21:9', Kling v4 21:9; Veo '16:9' / '9:16' |
| Named or pixel size | size |
Seedream '4K', '2K', '1536x864'; Wan 2.6 image '1024x768' |
| Video resolution | resolution |
Veo '1080p'; Vidu '540p'–'1080p'; Wan I2V '1080P' (capital P in docs) |
| Duration | duration |
Veo string '8s'; Vidu/Wan number seconds; Pixverse v6 up to 1–15 seconds |
| Audio | generate_audio, audio |
Veo 3.1, FLUX 3 video; Vidu audio: false for silent output |
Seedream 4.0 supports enhance_prompt. Seedream 4.5 and 5 Lite add sequential output via sequential_image_generation: 'auto' and max_images. Bria FIBO Generate 1.5 documents that resolution: '4MP' adds about 30 seconds of latency compared with 1MP in its examples.
Response shape: URL, base64, arrays, and jobs
Section titled “Response shape: URL, base64, arrays, and jobs”Most catalog REST examples return a envelope with state: "Completed", a result object, and often gatewayMetadata.keySource (Unified or BYOK for bring-your-own-key paths on models such as OpenAI GPT Image).
Parse output keys per model, not globally:
| Output pattern | When it appears |
|---|---|
result.image (string URL) |
Seedream 4.0, Wan 2.6 image, many Bria/OpenAI image models |
result.images[] |
Seedream 4.5+, Qwen Image 3.0 Pro with n variants |
result.video |
Veo 3.1, Vidu Q3, Bria v-rmbg 3.0, Topaz fast upscale |
result.audio |
ElevenLabs music v2 |
| Base64 on Worker response | @cf flux-1-schnell — response.image, not always the state/result wrapper |
| Task / job fields | MiniMax H3, Krea 3 — check status and URL fields in the doc snippet |
For masked edits, Bria FIBO Edit 1.5 documents that white areas of the mask are edited and black areas are kept. OpenAI GPT Image 2 with multiple images[] entries routes the call to OpenAI’s /v1/images/edits endpoint and supports up to 16 reference images for multi-edit workflows.
gatewayMetadata.keySource: Unified vs BYOK
Section titled “gatewayMetadata.keySource: Unified vs BYOK”Unified indicates Cloudflare’s unified billing/key path in newer examples. BYOK appears when the underlying provider expects your API key to be configured (common on OpenAI GPT Image and some Alibaba HH1 examples). The cluster does not document billing setup detail—treat BYOK as a signal to confirm key configuration before production use.
Background ai/run requests and webhooks for long jobs
Section titled “Background ai/run requests and webhooks for long jobs”By default, synchronous /ai/run calls keep the connection open until the model finishes. Cloudflare’s REST API — Background requests and webhooks states:
By default, /ai/run requests are synchronous — the connection stays open until the model finishes and the result comes back in the response. For long-running models — such as image, video, or audio generation — or when you do not want to hold a connection open, run the request in the background and have AI Gateway notify a webhook when it completes.
Set options.background: true and options.webhookUrl alongside model and input in the request body. The same page notes:
webhookUrl can only be provided when background is true. Providing a webhookUrl without background: true returns a 400 error.
Use background mode for video, music, and high-resolution image runs (for example google/nano-banana in the webhook example, or multi-megapixel Bria FIBO). Authentication for REST tests typically uses $CLOUDFLARE_API_TOKEN and account ID (see wrangler whoami / wrangler auth token in that doc’s examples).
AI Gateway vs catalog ai/run: Fal, Ideogram, and Replicate
Section titled “AI Gateway vs catalog ai/run: Fal, Ideogram, and Replicate”Not every third-party surface goes through the catalog body-only ai/run pattern.
Fal and Ideogram provider URLs
Section titled “Fal and Ideogram provider URLs”- Fal AI on AI Gateway — base
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal, headerx-fal-target-urlpointing at the Fal queue URL, auth with a Fal token or Cloudflare API token when using BYOK. - Ideogram on AI Gateway —
POSTto.../ideogram/v1/ideogram-v3/generatewith anApi-Keyheader.
Use these when you need the provider’s native HTTP API behind Cloudflare’s gateway, not the Workers AI model slug.
Pruna P-video on Replicate through AI Gateway
Section titled “Pruna P-video on Replicate through AI Gateway”The Pruna P-video tutorial explains:
This tutorial shows how to call the Pruna’s P-video ↗︎ model on Replicate through AI Gateway.
Endpoint pattern: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/replicate/predictions. Headers include Replicate Authorization, Cloudflare cf-aig-authorization, and optionally:
Prefer: wait — blocks until the prediction completes instead of returning immediately.
For runs expected under Replicate’s 60-second synchronous limit:
Because this is under Replicate’s 60-second synchronous limit, you can use the Prefer: wait header to send a request and get the result in a single call:
Longer renders should omit Prefer: wait, then poll GET .../replicate/predictions/{prediction_id} until status is succeeded or failed; the output field then holds the video URL. This path is not the same as env.AI.run('pruna/p-video', …) on the Workers AI catalog (Pruna P-video exists in-catalog, but the tutorial is gateway-specific).
Choosing a model family (image, video, enhance, utility)
Section titled “Choosing a model family (image, video, enhance, utility)”Use the model page as the source of truth; the table below groups common tasks from this cluster.
Text-to-image and editing
Section titled “Text-to-image and editing”- General T2I / tiers: FLUX family (flux-2-max, flux-3-image-klein), Seedream (4.0 → single
result.image; 4.5+ →result.images[]andimage_input), Recraft v4.x (many SKUs: raster, vector.svg, utility—differ by slug, sharedprompt+controls), Nano Banana line for grounded or multi-reference stills. - Edit / mask / layers: Bria FIBO Edit, Krea 3 (
image_urls[]), GPT Image 2 multi-image edit. - Fast Worker-native base64: @cf flux-1-schnell.
Text-to-video and image-to-video
Section titled “Text-to-video and image-to-video”- Google: Veo 3.1 (1080p,
generate_audio) vs Veo 3.1 Fast (examples emphasize 720p and shorter social clips); Gemini Omni usestext+resolution/aspect_ratio. - Alibaba: Wan 3.0 / Prime with
ratio: 'adaptive'; Wan 2.7 I2V withseedfor reproducibility. - Keyframes / references: Kling v4 (
first_frame,middle_frames[],last_frame, prompt@image_1refs); MiniMax H3 Max withcontent[]roles. - Duration / quality trade-offs: Vidu Q3 Turbo (up to 16s, 540p preview) vs Q3 Pro; Pixverse v6 supports 1–15 seconds per example headings.
Video post-processing and audio
Section titled “Video post-processing and audio”- Upscale / enhance: Topaz fast upscale Fast 2 vs Precise 2.6 (
sharpness); FLUX video upscale with creativity/prompt modes. - Background removal: Bria v-rmbg 3.0 on video URLs; Bria remove-background on images.
- Music: ElevenLabs music v2 →
result.audioURL.
Chaining video, frames, vision, and storage in Workers
Section titled “Chaining video, frames, vision, and storage in Workers”Bind Media Transformations to Workers shows clipping, frame extraction, and R2 upload via env.MEDIA.input(video).transform(…).output({ mode: "frame", time: "2s", format: "jpg" }), then feeding a frame into a vision model—for example env.AI.run("@cf/unum/uform-gen2-qwen-500m", { image: Uint8Array, prompt, max_tokens }).
To transcode a generated image before R2 storage, Transcode an image from Workers AI before uploading to R2 documents:
Transcode an image from Workers AI before uploading to R2
Flow: env.AI.run → image stream → env.IMAGES.input(stream).output({ format: "image/avif" }) → env.R2.put. That example uses @cf/bytedance/stable-diffusion-xl-lightning, illustrating another @cf/ ID alongside catalog bytedance/seedream-* slugs.
Utility outputs can be non-URL JSON: Bria Ad Delayer returns layered ad structures with message text such as “Constructed a layered ad.” in examples.
Common mistakes when calling image and video models
Section titled “Common mistakes when calling image and video models”- Wrong prompt field on Gemini Omni video (
text, notprompt). - Wrong response parser — especially
result.imagevsresult.images[]across Seedream versions; flux-1-schnell base64 onresponse.image. webhookUrlwithoutbackground: true→ HTTP 400 per background requests doc.- Mixing REST URL/body styles (catalog
model+inputvs@cfpath POST). - Assuming BYOK works without provider keys when
gatewayMetadata.keySourceisBYOK. - Duration type mismatch — Veo
'8s'strings vs Vidu integer seconds. - Calling Pruna only via
env.AI.runwhen your integration follows the Replicate gateway tutorial instead.
How to check this on your site
Section titled “How to check this on your site”-
Confirm account context with
wrangler whoamiand an API token with access to AI, as shown in REST API — Background requests and webhooks. -
Deploy or run a minimal Worker that calls
env.AI.runwith a model ID from that model’s page (for example Seedream 4.5 or Veo 3.1 Fast) and log the top-level keys you receive. -
Repeat the same input via
POST .../ai/runwithAuthorization: Bearer $CLOUDFLARE_API_TOKENand comparestate,result, andgatewayMetadatato the Worker response. -
For a long-running model, send
options: { background: true, webhookUrl: "https://…" }per REST API — Background requests and webhooks and confirm the immediate response plus webhook delivery; if using Replicate for P-video, test with and withoutPrefer: waitper Use Pruna P-video through AI Gateway. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match the linked Cloudflare documentation or your live API responses, email yimasynthetic@gmail.com with the page URL and the exact statement or model ID you are using so it can be corrected or clarified.