Latency, cost and fallbacks
Stream long answers, time out every call, cache stable prompt parts, price every call, and keep the feature useful when the provider is down.
- Required 4
- Recommended 4
- Optional 2
Required
Time out every model call
AIF-39Give every model call a total time limit and, when streaming, a limit on the silence between chunks. Retry only errors that may pass, and only before any output reached the user.
Price every model call and cap the spend
AIF-42Compute the cost of every model call from its token counts and record it with the feature and user. Enforce a daily budget per user and per feature.
Keep working when the provider fails
AIF-44Decide for each AI feature what happens when the model provider is down, slow or out of quota, and test that path. Use a second model that passed the same evals, a version without AI, or a clear message, never a hang or a broken page.
Make streamed answers work with a screen reader
AIF-46Announce a streamed answer to screen reader users once, when it ends, not piece by piece. Give every streaming answer a stop button that also cancels the model call.
Recommended
Stream long answers
AIF-38Stream any answer a person waits for that can take more than 2 seconds, and measure the time to the first token.
Put the stable part of the prompt first
AIF-40Order every prompt from most stable to least stable, with instructions, tool definitions and shared documents first and user input last. Turn on the provider's prompt caching, and measure the hit rate.
Keep every request inside a token budget
AIF-43Give every request a set input token budget and an explicit output limit. Trim conversation history and retrieved text by a fixed order before the call, never by letting the provider cut or reject it.
Route each kind of request to the model it needs
AIF-63When one feature gets requests of different difficulty, route each kind to the cheapest model that passes the evals for that kind. Decide the route in code and log it with every call.
Optional
Cache whole answers for repeated inputs
AIF-41Cache the full answer for features that give one right answer per input, such as classification or extraction. Key the cache on the prompt version, the model version and a hash of the input.
Send work nobody waits for as a batch
AIF-45Run large jobs that no person waits for, such as nightly tagging or re-summarising documents, through the provider's batch interface.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/latency-cost-and-fallbacks">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.