AI-103 courseLesson 12 of 18 · 12 min
Image and Video Generation on Azure: gpt-image, Sora and Inpainting (AI-103)
XUtilHub Team ·
Exam skills covered
- Implement a solution that generates images from text prompts and reference media
- Implement a solution that generates videos from text prompts and reference media
- Configure image-editing workflows, including inpainting, mask‑based edits, and prompt‑driven modifications
- Implement workflows to edit generated videos
- Select and apply appropriate generation and editing controls provided by the platform
The computer vision domain on AI-103 starts with generating visual content: images and videos from prompts and reference media, plus editing. Foundry offers image models such as gpt-image-1 and video models such as Sora, deployed like any other model.
Generate images from text
import base64
openai = project.get_openai_client()
result = openai.images.generate(
model="image-main", # your gpt-image deployment
prompt="Flat illustration of a friendly robot sorting invoices on a desk, brand colours indigo and white",
size="1536x1024",
quality="high",
n=1,
)
with open("robot.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))
Controls you can choose:
| Control | Examples |
|---|---|
| Size and aspect | 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait) |
| Quality | low, medium, high: trade cost and speed for detail |
Number of images (n) | Several variations to pick from |
| Output format and compression | PNG, JPEG, WEBP |
| Background | Transparent or opaque, where supported |
Better prompts are specific: subject, style, composition, lighting, colours and any text that must appear.
Generate from reference images
Pass reference images to keep a product, character or style consistent. The edit endpoint accepts one or more input images plus a prompt:
result = openai.images.edit(
model="image-main",
image=[open("product.png", "rb"), open("style-reference.png", "rb")],
prompt="Place the product from the first image on a kitchen counter, in the style of the second image",
)
Edit images: inpainting and prompt-driven changes
Inpainting changes only part of an image. Supply a mask: a PNG the same size as the image, where the transparent area is what may change.
result = openai.images.edit(
model="image-main",
image=open("living-room.png", "rb"),
mask=open("sofa-mask.png", "rb"),
prompt="Replace the sofa with a green velvet sofa",
)
Edit workflows:
- Mask-based edits: replace or remove an object, or extend the background
- Prompt-driven edits: "make it night time", "change the text on the sign to OPEN", with no mask
- Iterative edits: feed the previous result back in for step-by-step refinement
Generate videos
Video generation is asynchronous, because rendering takes time:
- Create a job with a prompt, plus optional reference image or video, duration, resolution / aspect ratio and number of variants
- Poll the job status until it succeeds
- Download the video (and often a thumbnail)
job = openai.videos.create(model="video-main", prompt="Drone shot over a foggy pine forest at sunrise", seconds="8", size="1280x720")
while job.status not in ("completed", "failed"):
time.sleep(10)
job = openai.videos.retrieve(job.id)
content = openai.videos.download_content(job.id)
Endpoint names and parameters differ between video model versions and API versions; check the current docs. The create → poll → download pattern is what matters.
Edit generated videos
- Remix: create a new version of a generated video with a changed prompt ("same scene, but in snow"), keeping structure and motion
- Image-to-video: animate a still image used as the first frame
- Extend or trim, and combine clips in your own pipeline (ffmpeg or a media service)
Choosing controls
| Requirement | Control |
|---|---|
| Fast, cheap drafts | Low quality, smaller size, short duration |
| Final marketing asset | High quality, correct aspect ratio, several variants |
| Consistent product look | Reference images |
| Change one region only | Mask (inpainting) |
| Social vertical video | 9:16 (portrait) size |
Safety and provenance
Image and video generation runs through content filters on the prompt and the output, and refuses disallowed requests such as sexual content, graphic violence, or realistic images of real public figures where policy forbids it. Generated media carries content credentials (C2PA) that mark it as AI-generated. Add your own checks for brand rules before publishing (covered in the next lesson).
Key takeaways
- Images:
images.generate(model, prompt, size, quality, n); edits with reference images and masks viaimages.edit. - Inpainting: the mask's transparent area is what changes.
- Video: asynchronous job → poll → download; remix and image-to-video for edits.
- Choose size, quality, count, duration and references to fit the use; generation is filtered and marked with C2PA credentials.
Next lesson: multimodal understanding and visual safety.
Check your understanding
Exam-style questions on this lesson. Get them all right to mark the lesson complete.
Finished reading?