AI MOOC
✦ Grow togetherInvite 3 friends, earn 1 month of membership · Up to 12 monthsInvite friends →

Library / My reading notes

Plan for failure, cancellation and cost

Define honest execution states and a budget for live requests.

Back to course plan: Design a bounded AI text assistant

Chapter 3 / 3 · Read and take notes

Define honest execution states and a budget for live requests.

Understand the method

Use explicit idle, running, complete, failed and canceled states. A timeout does not justify filling the result with a fixture. Explain whether the user should retry or change the input. Limit retries for transient failures; do not repeatedly retry invalid input or credentials.

Cost depends on provider, model and measured usage. Set output bounds, per-user quotas and a total budget, then reconcile provider receipts. Verify success, timeout, rate limiting and cancellation. Without live requests, describe your outcome as interface design and offline validation, not a working model integration.

  1. 1Set budget
  2. 2Bound execution
  3. 3Observe state
  4. 4Check receipts

Included material

Budget exercise: at most 10 daily calls, with at most 800 output tokens each. Leave prices blank until you choose a provider and record its current prices and verification date.

Work through the steps

  1. Write user messages and next actions for all four paths.
  2. Define timeout, retry bounds and cancellation behavior.
  3. Package the contract, validation results, state table and budget.

Worked example

Timeout: no complete result; retry later without a fabricated summary.
Rate limit: honor the service retry guidance, at most two retries.
Cancel: stop the request, keep input, label partial text incomplete.
Success: structure validated; check factual content against the source.

Your exercise

Complete the four deliverables and define the final state after two unsuccessful retries. If you optionally call a live model, keep actual status and usage and exclude credentials from notes.

Check before delivery

  • Failure and cancellation never appear as completion.
  • The budget distinguishes limits, estimates and actual charges.
Finish the exercise, then view the reference

After bounded retries, mark the request failed, preserve input and the reason, and allow a later user-initiated retry. Do not loop indefinitely or reuse an offline fixture as the result.

An original course with teaching exercises. Reading records, practice outcomes and independent certification are distinct.

References and further reading

The lessons are original. The following sources are provided under their respective permissions.

Course

Generative AI for Beginners

Microsoft · en/zh

MIT

License checked. This entry links to the original; the book text is not mirrored.

License checked: 2026-10-16 · Pinned d45da912
Course

Generative AI with JavaScript

Microsoft · en/zh

MIT

License checked. This entry links to the original; the book text is not mirrored.

License checked: 2026-10-16 · Pinned 03e41953
Book

Self-LLM: open LLM deployment guide

Datawhale · en/zh

Apache-2.0

License checked. This entry links to the original; the book text is not mirrored.

License checked: 2026-10-16 · Pinned e0fe14a3