Long-Context Reliability and Cost Tradeoffs
Understand how to predict and manage reliability and cost when handling long-context documents in Claude AI models. Learn techniques like selective context inclusion, prompt caching, token counting, and effort settings to optimize accuracy and control expenses, ensuring scalable and efficient deployments.
A procurement assistant that reads full supplier agreements works well in testing. Every answer cites the right clause, and the pilot users are happy. Then the customer runs it on ten thousand questions a day, and the monthly bill arrives far above the estimate, while a few answers about long agreements start missing details that the short test cases never exposed.
Both problems come from the same place. Every request carries its whole context, every token in that context costs money, and the more material a request holds, the harder it is for the model to use all of it well. FDEs are expected to predict these effects before launch and to know which controls change them.
The examples here use one shared document, a master supply agreement of about 5,000 tokens with terms and a long price schedule.
TERMS = """MASTER SUPPLY AGREEMENT between Harbor Manufacturing and Northline Seals1. Term. This agreement runs from 2026-01-01 to 2026-12-31.2. Pricing. Prices in the schedule are maximum unit prices. Orders above them need written approval from Procurement.3. Volume discount. An order of 1,000 or more units of one SKU receives 5% off the scheduled price.4. Delivery. The supplier delivers within 14 days of a confirmed purchase order.5. Late delivery. Each full week of late delivery reduces the invoice by 2%, up to 10%.6. Termination. Either party may end this agreement with 60 days' written notice."""ITEMS = ["gasket", "o-ring", "seal kit", "flange seal", "shaft seal", "valve seal"]# A long price schedule makes the agreement realistic in size, about 5,000 tokens.SCHEDULE = [f"SKU NS-{1000 + i}: {ITEMS[i % 6]}, size {10 + (i % 40) * 5} mm, maximum unit price ${0.50 + (i % 37) * 0.07:.2f}"for i in range(160)]AGREEMENT = TERMS + "\n\nPRICE SCHEDULE\n" + "\n".join(SCHEDULE)
Lines 1–7:
TERMSholds the agreement’s clauses, including the volume discount and the termination notice.Lines 12–15:
SCHEDULEbuilds 160 price lines, which gives the agreement a realistic size.Line 17:
AGREEMENTjoins the clauses and the schedule into one document.
Long context and its limits
A context window is everything a model can reference while it responds, including the response itself. Current Claude ...