01Chapter 1: How tokens turn into costThis chapter assumes you can read basic Python and have called an LLM chat or completion API before. You should know what a prompt, a system message, and a sampling setting such as temperature are. You should also be comfortable with HTTP APIs and JSON, because usage numbers come back in JSON respon6 min read
02Chapter 2: Where latency comes from: queueing, prefill, and decodingThis chapter assumes you have called an LLM API, can read basic Python, and know what a token is from the previous chapter. It breaks the wait for a response into stages. Later chapters on prompt trimming, output limits, streaming, and caching each target one of these stages, so you need to know whi6 min read
03Chapter 3: Measure first: build a cost and latency baselineThis chapter assumes you can call an LLM API from Python and read its response, including the token counts the provider reports. It also assumes you know what a streamed response is and have a rough idea of how tokens are priced. The chapter builds a small measurement harness and uses it to produce 5 min read
04Chapter 4: Protect quality with a small evaluation setEvery lever in this tutorial trades something for lower cost or latency. Shorter prompts, smaller models, output limits, and cached answers can all make responses worse. A small evaluation set (an "eval set") is how you find out whether a change broke something. This chapter shows how to build one, 6 min read
05Chapter 5: Pick the smallest model that meets the barYou have read the earlier chapters on token pricing, latency, measurement, and the small evaluation set. You can call an LLM API from Python. You have a baseline of cost and latency per request, and a labeled set of test cases with a scoring function. This chapter uses all three.6 min read
06Chapter 6: Trim the promptThis chapter assumes you can call an LLM API, know what system messages and sampling settings are, and can read basic Python. It also assumes you know that input tokens are billed and that prefill (the model reading your prompt) adds to time to first token. Earlier chapters covered both ideas. Here 6 min read
07Chapter 7: Limit and shape the outputOutput tokens usually cost several times more than input tokens, and they are produced one at a time. That makes output length the most direct lever on both cost and latency. This chapter assumes you know basic Python, have called a chat-style LLM API, and understand the tokens and latency chapters 6 min read
08Chapter 8: Streaming for perceived latencyThis chapter assumes you can call an LLM API with chat-style requests, read basic Python, and understand HTTP and JSON. It also assumes you have read the earlier chapters on latency anatomy and measurement. You should know that total latency splits into queueing, prefill, and decoding, and that time7 min read
09Chapter 9: Reuse stable prompt prefixes with provider cachingThis chapter assumes you can call an LLM API, know what system messages and tokens are, and have read the earlier chapters on token pricing, latency anatomy, and measurement. Here you will learn what provider prompt caching does, how to lay out prompts so it works, and how to check that it is workin6 min read
10Chapter 10: Budget retrieved contextThis chapter assumes you have built a retrieval-augmented generation (RAG) pipeline that embeds documents, searches for similar chunks, and pastes them into the prompt. It also assumes you know how input tokens are priced and how prefill delay affects time to first token, both covered in earlier cha6 min read
11Chapter 11: Cache full responsesResponse caching stores the complete answer to a request and returns it when the same request arrives again. A cache hit costs no tokens and returns in microseconds instead of seconds. This chapter covers how to build an exact-match cache, when it is safe, and the errors that cause stale or wrong an6 min read
12Chapter 12: Batch non-urgent workThis chapter assumes you can call an LLM API from Python, read JSON and JSONL, and know that input and output tokens are priced separately. It builds on the cost arithmetic from the tokens and pricing chapter.5 min read
13Chapter 13: Run requests in parallel without hitting limitsThis chapter assumes you can write basic Python, have called an LLM API, and know what an HTTP status code is. It also assumes you have seen async/await before. If you haven't, read the code slowly. The pattern is short.6 min read
14Chapter 14: Route requests and cascade between modelsThis chapter assumes you can call an LLM API from Python, that you have a small evaluation set (see the chapter on protecting quality), and that you have a cost and latency baseline. Routing and cascading only work if you can measure whether the cheaper path is good enough.6 min read
15Chapter 15: Set budgets and monitor in productionThis chapter assumes you have read the earlier chapters on token pricing, latency anatomy, and measuring a baseline. You should be comfortable with basic Python, JSON logs, and calling an LLM API. The goal is to turn the one-off baseline into limits and alerts that run all the time, so that cost and5 min read
16Chapter 16: Serving-side techniques for self-hosted modelsThis chapter assumes you have read the earlier chapters on tokens, latency anatomy, and measurement. It also assumes you can run Python and have a rough idea of what a GPU does. Everything here applies only if you run the model yourself. With a hosted API, the provider applies these techniques for y7 min read