CustomLabs
Topics

AI Cost & Efficiency

Inference cost rarely matches the per-token sticker price once retries, context growth, and fallback calls are counted. This is our work on modeling real AI spend and the build-vs-buy calls that keep it in check.

In the Handbook

Insights

Case studies

Failure modes

Retry-amplified spend

The estimate priced the happy path — one clean call per outcome. Production reality includes retries on malformed or rate-limited calls, fallbacks to a larger model when the first attempt fails, and agent loops that make several calls per completed task, and every one of those multiplies calls per successful outcome without multiplying the original per-token estimate.

Read

Prompt cache never hits

A dynamic prefix — a timestamp, a per-user greeting, a reordered tool list, retrieved chunks placed before the static instructions — changes the start of the prompt on every call, and prompt caching only pays off when the shared prefix is byte-identical across requests. One volatile token near the front is enough to bust the whole cache.

Read

Patterns

Model cascade

A cheap, fast model attempts every request first. A validation or confidence signal — a schema check, a self-reported confidence score, a downstream eval — decides whether that attempt is good enough to return, and only escalates to a stronger, pricier model on the fraction of requests the cheap one couldn't handle. Most traffic never reaches the expensive tier at all.

Read

Stable-prefix prompt caching

The prompt is ordered with everything invariant across calls first — system instructions, tool definitions in a fixed serialization order, few-shot examples — and everything that changes per request — retrieved chunks, user input, timestamps — placed last. Because prompt caching only pays off when the shared prefix is byte-identical across requests, one volatile token near the front is enough to bust the cache for the entire call; ordering invariant-first is what makes the discount actually apply.

Read

navigate select esc close