Begin with the unit you are paying for
A service can make three provider calls and finish only two useful tasks. Counting the average call price misses retries and human review. Begin by defining a task that a reviewer can accept, then retain every attempt made while completing it.
The first workbook supplies three invented attempt records. A1 fails, A2 completes the same task and B1 completes a second task. The result is a cost report with provider expense, review labor and cost per accepted task. No provider is contacted and no invoice or model performance is verified.
You need Python 3.10 or later, a text editor and a terminal. No packages or credentials are required. Allow about 15 minutes.
1. Inspect the records before running the calculation
Download the cost workbook and extract it into a new folder. It includes README.md, workbook.py, attempts.csv and expected-costs.txt.
Open attempts.csv. A task identifier stays the same across retries; each provider attempt has its own identifier. The accepted column records whether that attempt produced the completed task. Review seconds represent labor, not passive waiting. The example uses a fictional USD 20 hourly labor assumption, declared in the script.
2. Reproduce the full result
Open a terminal in the folder. Run python workbook.py costs, or substitute python3 if required by your installation. Complete expected stdout is:
attempts=3 tasks=2 accepted=2
provider_usd=0.0600 review_seconds=270 labor_usd=1.5000
full_cost_usd=1.5600
cost_per_accepted_usd=0.7800
data=synthetic model_calls=0 invoice_verified=no
Check it independently: provider cost is 0.02 + 0.03 + 0.01, or USD 0.06. The 270 review seconds equal 0.075 hours. At the assumed rate, labor costs USD 1.50. Dividing the recorded USD 1.56 by two accepted tasks produces USD 0.78 each.
“Full cost” in this output means the two recorded cost categories. Setup, training, maintenance and downstream repair are outside this tiny ledger. Add their declared allocation before treating a report as complete operating economics. The acceptance field also needs a quality rubric; the script cannot decide whether your real answer was useful.
3. Keep missing and failed evidence visible
Blank one provider-cost cell and rerun. Expect exit status 2 and ERROR: missing or invalid numeric evidence. An unavailable cost must not become zero.
Restore the file, then change every accepted value to no. The unit-cost line becomes cost_per_accepted_usd=UNDEFINED. The service still incurred expense, but it produced no accepted task to use as the denominator. Restore the reference data before comparing the original output.
Duplicate an attempt identifier and expect rejection. That protects this file from counting the same recorded attempt twice. It does not establish that an upstream provider exported every billable call.
Move from a workbook to service evidence
For your own service, map task and attempt identifiers before adding dashboards. Retain provider request identifiers privately where permitted, record usage state explicitly and reconcile totals with billing evidence. Assign review labor according to a declared policy. Track failures and manual fallback alongside acceptance.
The next engineering decision might involve retrieval, where a service finds source material before generating an answer. The published retrieval lesson below tests whether stale or unauthorized documents can enter that evidence set. It is an integration boundary, not a complete deployed answer service.
You are finished when you reproduce the original report, explain why failed A1 remains in cost, and demonstrate both missing-cost rejection and undefined unit cost. If Python cannot find the script, open the terminal in the extracted folder. Preserve the CSV headers and use decimal values without currency symbols.
The journal progresses from measurement to integration, deployment and recovery. Each lesson must identify which part was actually executed and what operational evidence remains missing.