Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
These projects have a real cash cost, and it is concentrated in a few operations: running an extraction pass over every document, generating a distillation training set from a frontier model, and any agent loop without a ceiling. Each of those can run away silently because the per-call cost is trivial and the call count is not. Estimating first is not just financial hygiene — the estimate is itself a portfolio artifact, because cost transparency is one of the things you are trying to demonstrate. An engineer who can say what their pipeline costs per document is signalling something different from one who cannot.
Estimate on a sample before you run the full set, and cache by content hash so a re-run is free. The cache is not an optimisation, it is what lets you iterate on prompts without paying twice.
import hashlib, json, pathlib
CACHE = pathlib.Path(".cache/extract")
CACHE.mkdir(parents=True, exist_ok=True)
def estimate(docs, sample_n=10, price_in=3.0, price_out=15.0):
"""Run on a sample, extrapolate, then decide. Prices are $ per 1M tokens."""
sample = docs[:sample_n]
tok_in = sum(len(d) // 4 for d in sample) # ~4 chars per token
tok_out = sample_n * 800 # measured, not guessed
per_doc = (tok_in / sample_n / 1e6 * price_in) + (tok_out / sample_n / 1e6 * price_out)
total = per_doc * len(docs)
print(f"per doc ~ ${per_doc:.4f} | {len(docs)} docs ~ ${total:.2f}")
return total
def extract_cached(doc_text: str, fn):
"""Content-addressed cache. Re-running after a prompt tweak only pays
for the documents whose text actually changed."""
key = hashlib.sha256(doc_text.encode()).hexdigest()[:16]
path = CACHE / f"{key}.json"
if path.exists():
return json.loads(path.read_text())
result = fn(doc_text)
path.write_text(json.dumps(result))
return result
# Guardrail worth adding on day 1:
MAX_SPEND_USD = 25.0 # process aborts rather than surprising youpython3 main.py