In this video, you lowered the output limit to make the tea importer’s drafts cheaper, watched every draft get cut off mid-sentence, and taught ask() to say when that happens so the draft script can hold a cut-off draft back.
Key Points
- A lower output limit doesn’t give you a shorter reply. With
MAX_OUTPUT_TOKENS=50, every draft was cut off mid-sentence: Priya’s stopped partway through a sentence about caffeine, Marcus’s at “I’d be happy to check wholesale”, and Hannah’s in the middle of the signature, at “Leaf & K”. Where yours stops will differ. Each draft did cost less: 50 output tokens, about 0.07 cents, down from about a tenth of a cent. - The model doesn’t plan around the limit. The limit travels in the request as a setting the provider applies, not as text the model reads: the model reads only the instructions and the email. It generates its reply the same way it would with no limit, one token at a time, and the provider stops it at the limit, even mid-word. Reasoning tokens count toward the limit too.
- A cut-off call still succeeds. The script finished normally,
ask()threw no error, and you paid for all 50 tokens. Only the stop reason says the reply was cut off. ask()turns the stop reason intocutOff. Each provider has its own word for “hit the output limit”, so you add it to each provider file as a constant,CUT_OFF(your provider’s line is below).adapterholds everything its provider file exports, soadapter.CUT_OFFis your provider’s word.ask()compares the reply’s stop reason with it and addscutOff,trueorfalse, to every result. Your feature code never needs a provider’s word.cutOff: falseisn’t a guarantee. It only means the limit didn’t stop the reply. It doesn’t promise a usable draft.- Hold a cut-off draft back. The draft script checks
reply.cutOff, prints a “Held back” line, and moves on withcontinue, so the draft’s text is never used. You still pay for every token the provider generated, finished or not. - Ask for length in the instructions. The model usually follows a length you ask for there, not always, so the cap and the
cutOffcheck stay. With “under 40 words” in the instructions and the limit back at 400, the drafts took 55, 47 and 43 output tokens. That’s the saving you wanted: about what the cut-off ones cost, under a tenth of a cent, and every draft was finished and signed. Your drafts will differ in wording.
The rule: the output limit stops a reply, it doesn’t shorten it. Ask for length in the instructions, keep the limit as a safety cap well above the reply you expect (400 here, against drafts of about 50 tokens), and check cutOff before you use a draft.