Lesson 2 of 3 Computer Vision Applications in Foundry

Generating and Editing Images and Video in Foundry

This lesson explains how Foundry's image models create new images from text and edit existing ones, how video models create short clips, and the parameters and practices for producing visual output.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the image models available and the images playground.
  • Describe the parameters of images.generate() and images.edit().
  • Apply good prompting, cost and responsible-use practices.
  • Explain why the videos API is asynchronous.

Image models and the images playground

Image models are deployed from the catalog like other models. The GPT-image models from OpenAI, such as gpt-image-2 and the lower-cost gpt-image-1-mini, follow detailed instructions and render text well; FLUX models from Black Forest Labs are also available. Some image models require an access request before deployment. The Foundry portal's images playground lets you enter a prompt, choose size, quality and the number of images, and view the results and sample code.

True or false

Image models in Foundry

Exam skills 2.3.2

Check four statements about image models and the images playground.

Log in to try this activity Interactive activities are free with an account.

Generating and editing in code

Applications call the images API through an OpenAI client. images.generate() takes the deployment name, a prompt, a size such as 1024x1024 or 1536x1024, a quality of low, medium or high, and n for the number of images. GPT-image models return each image as base64 data in data[i].b64_json, which the application decodes and saves.

import base64
result = client.images.generate(
    model="image-gen",                           # deployment name of the image model
    prompt="Flat illustration of a lighthouse at dusk, warm colours, no text",
    size="1024x1024", quality="medium", n=1,
)
open("lighthouse.png", "wb").write(base64.b64decode(result.data[0].b64_json))

images.edit() takes one or more input images and a prompt, for example to change the background or combine products into one scene. Adding a mask, an image of the same size whose transparent pixels mark the area to change, restricts the edit to that region (inpainting).

Spot the bug

A broken image file

Exam skills 2.3.2

Find the lines that stop this script from saving a usable image.

Log in to try this activity Interactive activities are free with an account.

Prompting, cost and responsible use

Good image prompts describe the subject, setting, style, composition, lighting and exclusions, and are refined one change at a time. Cost and latency rise with quality and size, so drafts use low quality. Guardrails filter harmful prompts and images, and images generated by Azure OpenAI models include C2PA content credentials that mark them as AI-generated.

Video generation

Video-generation models generate short clips from a prompt and, optionally, a reference image. Because generation takes minutes, the videos API is asynchronous: the application creates a job, polls its status until it completes and then downloads the content; some models can also remix an existing clip with a change. Video models are offered in fewer regions and change often. OpenAI's Sora models were offered in Foundry until the last version retired in October 2026, so check the catalog for current availability before planning a solution.

Scenario questions

Generate, edit or wait

Exam skills 2.3.2

Choose the right images or videos API pattern for each request.

Log in to try this activity Interactive activities are free with an account.
Worked example

Generate or edit

A marketing team has a photo of its new backpack and wants (1) three illustrated concept images for a campaign theme and (2) the backpack photo with only the sky behind it changed to a sunset.

(1) is images.generate() with n=3 and a descriptive prompt. (2) is images.edit() with the photo and a mask over the sky, so the backpack itself is unchanged. Generating (2) from text alone would not reproduce the real product.

Check yourself

How can an edit be limited to one region of an image?

Show answer

With a mask passed to images.edit().

Exam Tips

Remember for the exam

  • images.generate() creates images; size, quality and n control output, cost and time.
  • images.edit() modifies input images; a mask limits the change to a region.
  • Video generation is an asynchronous create, poll and download job.