Module 2 — Controlling the Output
Goal: precise, predictable, cost-aware text generation.
Module 1 got you a working call, and a safe one. But every function you’ve written so far hands control entirely to the model. You don’t decide how creative the wording is, how long the answer runs, or what shape it comes back in, you just get whatever the model feels like giving you and hope it’s usable.
This module is about taking some of that control back. Six chapters, and none of them introduce a new mental model, they’re all just new configuration on the same generate_text() call you already know.
What’s in this module
- The Creativity Dial, Temperature. Why the same prompt gives you different wording every time, and the setting that controls how much.
- Don’t Blow the Budget, Max Tokens. What a token actually is, and why it affects both response length and what the site owner pays.
- Ask for JSON, Not Prose. The chapter that changes what AI output is actually useful for. Instead of a paragraph you paste into a textarea, you get structured data your plugin can save, loop over, and act on.
- Using the Data, Saving JSON to Post Meta. Taking that structured response and actually keeping it, instead of just printing it and letting it vanish on the next page load.
- Give Me Options, Multiple Variations. Getting several candidate answers back from one call, so a user can pick instead of settling for whatever came back first.
- Fine-Tuning Generation, Top-P, Top-K, and Stop Sequences. The less commonly needed settings, worth knowing exist and roughly what they do, even if you reach for them less often than temperature.
Why these six belong together
Every chapter in this module answers some version of the same question: the AI gave you an answer, but not quite the answer you needed, too random, too long, in the wrong shape, only one option when you wanted three. None of that means the AI Client is missing something. It means there’s a configuration method for it, and you haven’t met it yet.
By the end of this module you’ll be chaining three or four of these onto a single builder without thinking about it, the same way you already don’t think twice about adding a WHERE clause to a WP_Query args array.
One practical note before you start. Some of these settings behave differently, or not at all, depending on which specific AI model your connected provider defaults to (reasoning models in particular tend to ignore several of them). If a chapter’s example doesn’t match what’s described, that’s very likely why, and several chapters flag it directly when it’s a known issue. There’s a proper fix for choosing a specific model, using_model_preference(), but it’s not covered until Chapter 19. If you get stuck before then, ->using_model_preference( 'model-id' ) chained onto any builder in this module is a safe early preview, just enough to route around a problem model without needing the full chapter yet.
On to Chapter 6.