Skip to content

Module 3 — Beyond Text

Goal: images and mixed-media output.

Every chapter so far has done one thing: sent a prompt, gotten a string back. Different configuration, same shape of result. This module breaks that pattern. We’re generating images now, and the AI Client handles them through the same builder you already know, just pointed at a different generation method.

What’s in this module

  1. Your First AI Image. A new method, generate_image(), and a new kind of return value, a file object instead of a string.
  2. Image Variations and Output Control. Getting several image options from one call, and controlling the file type and orientation you get back.
  3. Text and Images Together, Multimodal Output. Requests that return a genuine mix, paragraphs and images interleaved in one response, not two separate calls stitched together afterward.

One thing worth knowing before you generate your first image

Image generation typically costs more per call than text generation does, sometimes considerably more, depending on the provider. Nothing in this module requires spending real money to follow along (check back to Chapter 1 if you still need a free-tier key), but where Module 2’s examples were cheap enough to reload a dozen times without thinking about it, I’d be a little more deliberate about how often you re-run the examples in this one.

We also haven’t covered checking whether a site’s connected provider even supports image generation before trying to use it, that’s Chapter 17, further along. For now, just try it. If your provider doesn’t support images, you’ll get a clear WP_Error back, and Chapter 3’s pattern already has you covered.

Same practical note as Module 2’s intro applies here too, maybe more so. Image models vary a lot by provider and by which specific model your connector defaults to, some don’t support requesting more than one image per call, some are simply slow enough to time out under a fixed request window. If a chapter’s demo doesn’t behave as described, an early preview of using_model_preference() (->using_model_preference( 'model-id' ), properly covered in Chapter 19) is worth trying before assuming your own code is wrong. It won’t fix everything, a couple of the issues in this module turned out not to be fixable by switching models at all, but it’s a reasonable first thing to try.

On to Chapter 12.

This book is created with Chapterwright