Image & Video Generation
gpt-image models · Image API · edits and masks · Sora 2 · video jobs · remix · content controls
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Models and ways to call them
| Need | What Microsoft Learn shows | Notes |
|---|---|---|
| Text to image | GPT-image family (for example GPT-Image-1, GPT-Image-1-Mini, GPT-Image-1.5) deployed in a Foundry (Azure OpenAI) resource | Test in the Foundry playground, or call the image generation API or the Responses API |
| Image to image and edits | The same GPT-image models take text plus image inputs | Edits go to the image edit API |
| Text, image or video to video | Sora 2 (text to video, image to video, video to video remix) | Uses the Azure OpenAI v1 API; audio can be generated |
| Third-party image and video models | FLUX (image) and a model family from Fal (video) are available in Foundry | Named on the training module |
| Retired | The dall-e-3 model was retired on March 4, 2026 | Existing deployments are non-functional; use a gpt-image series model |
- Deploy the model first: in Foundry go to Models + endpoints, select Deploy model, pick the model, then Open in playground. The deployment name is what you pass as the model value in code.
- Authenticate with an API key or Microsoft Entra ID. With managed identity, the identity needs the Cognitive Services OpenAI User role on the resource (image troubleshooting section).
- The playground can show Python and cURL code that is prefilled from your settings (View code).
Generate images from text and reference media
Two paths: the image generation API (client.images.generate, or a POST to /openai/v1/images/generations) and the Responses API with the image_generation tool.
| Setting | What it does | Stated values |
|---|---|---|
model | Your deployment name | For example gpt-image-1.5 in the sample |
size | Output dimensions | GPT-image-1 series: 1024x1024, 1024x1536, 1536x1024; square is faster. gpt-image-2: arbitrary sizes, both edges a multiple of 16, long edge up to 3840 px, aspect ratio up to 3:1 |
n | Images per call | 1 to 10, default 1 |
quality | Quality against speed | Lower quality images can be generated faster |
output_format | File format | PNG or JPEG, default PNG; WEBP is not supported |
output_compression | Compression level | 0 to 100, default 100 |
background | Transparent background | Set to transparent with PNG output |
user | Unique user identifier for tracking and monitoring usage | Any string |
stream, partial_images | Get partial images while generating | Use the image generation API; the Responses API tool does not stream |
- GPT-image-1 series models always return base64 data: read
b64_jsonand decode it.response_formatis not supported. - Default image generation quota per deployment is 5 images per minute for the GPT-image-1 series and gpt-image-2. A 429 error means the rate limit was exceeded; wait, retry, or request more quota.
- Image generation typically takes 10 to 30 seconds, and complex prompts can take up to 60 seconds. Streaming gets partial results sooner.
- The Responses API tool accepts image file IDs as input in addition to raw bytes and supports multi-turn editing of images.
Edit images: inpainting, masks and prompts
| Item | Rule |
|---|---|
| Endpoint | .../openai/deployments/<deployment>/images/edits (an input image is required) |
| Body type | multipart/form-data, not JSON |
| Input images | Up to 16; each under 50 MB; PNG or JPG |
mask | PNG with the same dimensions as the input image; fully transparent pixels (alpha of zero) mark the area to edit |
input_fidelity | Matches style and features, especially faces, of the input; not supported by gpt-image-1-mini |
| Without a mask | Send the image and a prompt that describes the change (prompt-driven edit) |
Mask-based edit = edits endpoint + PNG mask + same size as the image. A JSON body or a different-size mask is the usual wrong answer.
Generate and edit video with Sora 2
Video generation is an asynchronous job: create the job, poll its status, download the video once it is completed. It typically takes 1 to 5 minutes.
- Create:
client.videos.create(model=..., prompt=...)(REST: POST to/openai/v1/videos). The response has a video id and a queued status. - Poll:
client.videos.retrieve(video.id). Expected states:queued,in_progress,completed,failed. - Download:
client.videos.download_content(video_id, variant="video"), thenwrite_to_file(REST: GET/videos/{video_id}/content?variant=video).
| Control | Meaning |
|---|---|
prompt | Shot type, subject, action, setting, lighting, camera motion; keep it single-purpose |
size, seconds | Output resolution and length (also settable in the Video playground) |
input_reference | One reference image used as a visual anchor for the first frame; its resolution must match the output size |
remix_video_id / client.videos.remix | Change a completed video: keeps its framework, scene transitions and layout; limit each remix to one clearly stated adjustment |
- Update the OpenAI client (
pip install openai --upgrade) ifvideosis missing (AttributeError). - Two video creation jobs can run at the same time; jobs are available for up to 24 hours after creation.
- Write prompts in English or other Latin script languages for the best performance. The page lists difficulty with complex physics, spatial reasoning and precise timing.
Safety rules on generation
- Image and video APIs have a content moderation filter. A flagged prompt returns an error with
error.codeset tocontentFilter; the generated image itself can also be filtered. - Photorealistic images of minors are blocked by default for the image models.
- Sora 2 rejects copyrighted characters and music, cannot generate real people (including public figures), and currently rejects input images with human faces.
- A failed video job: check
failure_reasonand change the prompt if it triggered content filtering.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Generate an image (Python, OpenAI client) | client.images.generate(model="gpt-image-1.5", prompt="A cute baby sea otter", n=1, size="1024x1024", stream=True, partial_images = 2) | - |
| Generate an image with the Responses API tool (Python) | response = client.responses.create(
model="MODEL_NAME",
input="Generate an image of a gray tabby cat hugging an otter with an orange scarf.",
tools=[{"type": "image_generation"}],
) | - |
| Create a Sora 2 video job (Python) | video = client.videos.create(
model="sora-2", # Replace with Sora 2 model deployment name
prompt="A video of a cool cat on a motorcycle in the night",
) | - |
| Poll a video job (Python) | client.videos.retrieve(video.id) | - |
| Download the finished video (Python) | client.videos.download_content(video_id, variant="video") | - |
| Remix a completed video (Python) | video = client.videos.remix(
video_id="<previous_video_id>",
prompt="Shift the color palette to teal, sand, and rust, with a warm backlight."
) | - |
Exam Tips
Tick each tip once you can answer it without looking.
“App still calls a dall-e-3 deployment and fails” → The model was retired on March 4, 2026: deploy a gpt-image series model and use its deployment name. Trap: Quota or API changes do not revive a retired model.
“Image result: URL or bytes?” → GPT-image-1 series always returns base64 in b64_json; response_format is not supported. Trap: Do not plan on a downloadable link.
“Several candidate images from one request” → Set n (1 to 10, default 1). Trap: partial_images is for streaming; user is an identifier.
“Change part of a picture, keep the rest” → Image edit API (/images/edits) with multipart form data, the image, a prompt and a PNG mask. Trap: The generations endpoint creates a new image from JSON.
“Which pixels does the mask edit?” → Fully transparent pixels (alpha of zero); PNG, same dimensions as the input image. Trap: A JPEG or different-size mask does not meet the rule.
“Edit request limits” → Up to 16 input images, each under 50 MB, PNG or JPG. Trap: WEBP is not an accepted input type on the page.
“Keep faces close to the original in an edit” → input_fidelity; not supported by gpt-image-1-mini. Trap: quality trades quality against speed (low, medium, high); it is a different setting.
“Show partial images while generating” → Image generation API with stream true and partial_images. Trap: The Responses API image tool does not stream.
“Logo with a transparent background” → background = transparent with PNG output. Trap: WEBP is unsupported; JPEG is not the stated pairing.
“429 from the image API” → Rate limit exceeded: back off and retry, or request more quota (default 5 images per minute). Trap: It is not an authentication error; 401 is.
“Video from Sora 2: how does the call work?” → Async job: create, poll until completed, then download the MP4. Trap: Download works only after the status is completed; create returns a video id and a queued status.
“Sora 2 job states” → queued, in_progress, completed, failed. Trap: The older job API shows succeeded; use the v1 Sora 2 states here.
“Animate a still image with Sora 2” → input_reference: one image, first-frame anchor, resolution must match the output size. Trap: A mismatched size is the common wrong setup.
“Tweak a finished video (palette, mood) and keep the layout” → client.videos.remix with the completed video id and a new prompt. Trap: A fresh create regenerates from scratch; keep each remix to one adjustment.
“Prompt names a real public figure or uses a face photo (Sora 2)” → Rejected: real people cannot be generated and face input images are rejected. Trap: Copyrighted characters and music are rejected as well.
“Prompt flagged by the filter on an image call” → Error with error.code = contentFilter; change the prompt. Trap: The output image can be filtered too, with a different message.
Sources
- Image generation models in Foundry (training unit)
- Video generation models in Foundry (training unit)
- How to use image generation models from OpenAI
- Sora 2 video generation overview
- Responses API (image generation tool)
Checked against Microsoft Learn on November 13, 2026.