What it actually costs to make LLMs production-ready. The 80% of AI product engineering that has nothing to do with AI.
The API call takes 3 seconds. The infrastructure around it took
3 months.
Every AI product demo follows the same script: call the API, get a response, show the result. Three steps. A weekend project.
Then you ship it to real users and discover that the LLM call is the easy part. The hard part — the part that takes 80% of the engineering time — is everything around it: validating unpredictable responses, handling timeouts across chunked pipelines, preventing double-charges on concurrent requests, and building fallback tiers so users always get a result.
We call this the AI tax — the infrastructure cost of making an LLM feature production-ready. It’s invisible in demos, absent from tutorials, and consistently underestimated by 5-10x.
What stakeholders imagine
1
User Input
Text, files, or a question
2
LLM Call
Send to the model, get a response
3
Display Result
Show the output to the user
Three steps. Clean. This is what gets budgeted for.
What actually ships
The real pipeline for a single AI feature has seven infrastructure layers surrounding the LLM call. Each layer exists because we shipped without it and watched it fail.
1
Preprocessing
Date extraction (chrono-node), document summarization (HuggingFace BART), chunking at sentence boundaries with overlap
2
Input Validation
Zod schema validation on every input. Prompt injection defense via input sandwiching. Domain-specific parsing guidance injection.
3
Timeout Management
AbortController on every fetch. Per-chunk timeout budgets. Total pipeline timeout that prevents one slow chunk from stalling everything.
4
Response Validation
Tier 1: full Zod schema validation. Tier 2: validate individual items if full schema fails. Tier 3: regex extraction from raw text as last resort.
5
Billing Guard
Check balance before execution. Run the AI pipeline. Charge only on success. Atomic database update prevents race-condition overdrafts.
6
Error Recovery
Summarization falls back to intelligent truncation. Parsing falls back to partial results with warnings. Users always get something.
7
Cleanup
Assistants and uploaded files deleted in finally blocks. No orphaned resources. Credit refunds on failure. Audit trail on every transaction.
Where the engineering time actually goes
This is what the proportion looks like across two shipped AI products (Chronologiq and RecommendMe):
Preprocessing
Validation
Timeouts
Response handling
Billing
Error recovery
Cleanup
Prompts + LLM
Preprocessing18%
Validation15%
Timeouts8%
Response handling15%
Billing14%
Error recovery12%
Cleanup6%
Prompts + LLM12%
The highlighted segment — the actual LLM prompt engineering — is 12% of the total effort. Everything else is the tax.
The seven layers, unpacked
Documents over 8K characters are split into 3K chunks at sentence boundaries with 200-character
overlap. Each chunk is summarized by HuggingFace BART (a dedicated summarization model) before
the generative LLM ever sees the content. A total timeout budget of 120 seconds across all
chunks prevents pipeline stalls. If summarization fails, intelligent truncation ensures the user
still gets a result.
Separately, chrono-node pre-extracts date references from the raw text — giving the LLM
deterministic date hints instead of asking it to parse natural language dates (which it does
poorly).
Every API input is validated against a Zod schema before touching the LLM pipeline. But
validation goes beyond type checking — input sandwiching wraps user content in system-level
markers, making prompt injection attempts structurally visible to the model. Domain-specific
parsing guidance (stored per-canvas in the database) is injected into the system prompt so the
LLM has context without the user needing to provide it.
Every external call — to Azure OpenAI, to HuggingFace, to Supabase — uses an AbortController
with a configurable timeout. Summarization has its own per-chunk and total timeout budgets so
that one slow HuggingFace response doesn’t stall a 10-chunk document. The LLM generation call
has a separate timeout from the validation calls. AbortError is caught specifically and surfaced
as a user-friendly timeout message, not a generic 500.
Tier 1: Validate the complete LLM response against a Zod schema. If the JSON
structure matches, use it directly.
Tier 2: If the full schema fails, iterate through individual items in the
response and validate each one. Return the valid items with a warning about partial results.
Tier 3: If JSON parsing fails entirely, regex-extract structured fields from
the raw text response. This catches cases where the LLM returns almost-valid JSON or wraps its
response in markdown code blocks.
Phase 1 (Check): Verify the user has enough credits before starting. Phase 2 (Execute): Run the
full AI pipeline — preprocessing, LLM call, response validation. If any step fails, the user
pays nothing. Phase 3 (Charge): Only after successful completion, atomically deduct credits. The
database update uses a conditional guard (.gte(‘balance’, amount)) that prevents
race-condition overdrafts when concurrent requests hit the same user balance.
If BART summarization fails → fall back to intelligent truncation (preserving sentence
boundaries). If full LLM response validation fails → return partial valid results. If the LLM
times out → surface a clear message with the option to retry. If date extraction finds nothing →
the LLM proceeds without date hints rather than failing. The principle: every failure mode has a
degraded-but-useful output path.
RecommendMe creates a fresh Azure OpenAI assistant per generation request with uploaded files.
Both the assistant and files are deleted in a finally block — even if generation
fails. Every credit transaction creates an audit trail entry with the balance-after snapshot.
Failed operations log the failure type and stage for debugging without exposing internals to the
user.
The takeaway
If you’re scoping an AI feature, multiply your LLM-integration estimate by 5-8x. That’s not pessimism — it’s the real cost of:
Making outputs trustworthy (validation + grounding)
Making failures invisible (recovery + fallbacks)
Making billing fair (charge-on-success)
Making the pipeline resilient (timeouts + cleanup)
The LLM call is the seed. The tax is the garden.
Already paying the AI tax? We can audit your pipeline.