Lesson 1 of 3 Image and Video Generation

Generating Images from Text and Reference Media

This lesson explains the image generation models available in Foundry, how to call them and how to choose generation controls, for images created from prompts and optionally guided by reference images.

Learning outcomes

After completing this lesson, you will be able to:

  • Call GPT-image models through the images API.
  • Use reference images with images.edit.
  • Choose generation controls such as size, quality and background.

Models and APIs

An image generation model creates a new image from a text description, called a prompt, and optionally from one or more reference images. Like other models, it must be deployed from the Foundry Models catalogue before an application can call it, and it is called through a dedicated images API rather than the text APIs.

GPT-image models, such as gpt-image-2, are deployed from Foundry Models and called through the images API on the v1 endpoint, or used as the image generation tool from the Responses API and agents. The catalogue also includes partner image models such as FLUX models from Black Forest Labs. GPT-image models follow detailed prompts closely, render text in images well and can use several reference images.

import base64
result = aoai.images.generate(
    model="image-gen",                     # deployment of a GPT-image model
    prompt=("Product photo of a matte black insulated water bottle on a light oak desk, "
            "soft window light from the left, shallow depth of field, no text"),
    size="1024x1024", quality="medium", n=1,
)
open("bottle.png", "wb").write(base64.b64decode(result.data[0].b64_json))

The response contains base64-encoded image data rather than a permanent URL, so the application stores the image, for example in Blob Storage, together with the prompt and settings used.

Reference media

To generate an image that uses existing visual material, such as a product photo, a logo or a style sample, the application calls images.edit with one or more input images and a prompt that says how to use them: "Place the bottle from the first image on the hiking trail in the second image". The input fidelity setting controls how closely distinctive details such as faces, logos and product shapes are preserved. Reference images must be suitable for the use; images of real people or third-party brands carry legal and policy considerations.

Scenario questions

Generate the image

Exam skills 3.1.1

Practise choosing the images call and settings for each request.

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

Generation controls

Generation controls are request parameters that shape the image without changing the prompt. They matter because image generation is slow and costly compared with text, so choosing the right settings for each stage of a workflow saves both time and money. size sets the aspect ratio, which should match where the image will appear: a square product tile, a portrait phone screen or a landscape banner. quality trades detail against speed and cost, so drafts and thumbnails use low quality and only approved images are regenerated at high quality. n requests several candidates in one call, which suits workflows in which a person chooses the best option.

Further controls concern the output file and the use of references. output_format and output_compression choose PNG, JPEG or WebP and the compression level, which affects file size on the web. background can request a transparent background, which only PNG and WebP can store, for logos and images placed over other content. In edits, input_fidelity decides how closely distinctive details of the input images, such as faces, logos and product shapes, are preserved. The following table summarizes the controls.

ControlValuesUse
sizeSquare, portrait, landscape (for example 1024x1024, 1024x1536, 1536x1024)Match the layout where the image will appear
qualitylow, medium, highLow for drafts and thumbnails; high for final assets
nNumber of imagesGenerate options for a person to choose
output_format, output_compressionPNG, JPEG, WebP; compression levelSmaller files for the web
backgroundtransparent or opaqueTransparent PNG or WebP for overlays and logos
input_fidelitylow or high (edits)Preserve faces, logos and product details from inputs

Higher quality and larger sizes increase latency and cost. Prompts that request disallowed content are rejected by the guardrail with a content filter error, which the application handles by showing a clear message.

The following screenshot shows the image playground of a gpt-image-2 deployment after one generation from the prompt Product photo of a light oak armchair with a sage green cushion in a bright Scandinavian living room, soft morning light, plain white wall, catalogue style. The prompt bar below holds the size (1024x1024) and quality (Low) controls.

gpt-image-2 playground with a generated armchair image and the size and quality controls
Low quality is the fastest and cheapest setting for drafts; higher quality suits final images.
Match the pairs

Image generation controls

Exam skills 3.1.5

Match each GPT-image control with when to use it.

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

Catalogue images

An online store needs lifestyle images of 500 products, each showing the exact product from its studio photo in a realistic setting. Designers will review three options per product, and final images must have transparent backgrounds for one layout.

Use images.edit with the studio photo as reference and high input fidelity so the product is preserved, generate three options at medium quality for review, and regenerate the chosen option at high quality. For the transparent layout, request PNG output with a transparent background. Using images.generate from text alone would not reproduce the exact products.

Check yourself

Which output formats allow a transparent background?

Show answer

PNG and WebP.

Exam Tips

Remember for the exam

  • Text only: images.generate. Using existing images: images.edit with the images as input.
  • High input fidelity preserves faces, logos and product details.
  • Transparent background requires PNG or WebP output.