Most production AI bills balloon because teams treat a large language model as a general-purpose runtime. Demos that send every step through an LLM become expensive in production when volume, retries, and long prompts multiply. This white paper maps how Hong Kong SMEs and startup operators can separate deterministic application logic from probabilistic inference, so monthly API spend stays predictable while latency, reliability, and auditability improve.
Inside the report
- The four hidden cost multipliers that turn cheap pilots into unpredictable API invoices.
- The Code vs. Model boundary matrix: what belongs in SQL and code, a fast model, or a frontier model.
- Five production patterns from real SME workflows (gatekeeping, state machines, compile-once lookup, verification gates, log-to-rule promotion).
- A worked unit-economics walkthrough at 10,000 monthly enquiries, with derived line items and a slider that shows how step count changes model spend.
- Quality gates and canary rollout before you downgrade a model tier.
- Governance, OWASP LLM risks, and Hong Kong PCPD-aligned controls that prompts alone cannot enforce.
- A 14-day audit checklist to refactor one live workflow without halting operations.
Full paper
Continue with your work email
We use your email to share this white paper and occasional notes on AI delivery. Unsubscribe anytime.
Overview
Executive summary
One rule for production AI spend: put rules in code, reserve models for language and judgment.
When teams move AI from a demo into daily operations, API spend often grows faster than usage. At the same time, a single unchecked error can pause rollout. Both problems share a root cause: treating an LLM as a general-purpose runtime.
Use deterministic code for known rules, schemas, permissions, state transitions, and arithmetic. Reserve LLM inference for unstructured input, ambiguity, synthesis, and nuanced drafting.
- Predictable unit economics: Spend tracks genuine language complexity, not retries or static context bloat.
- Lower latency: Validators and SQL run in milliseconds without hallucination.
- Auditable controls: Boundaries live in testable code, aligned with AI cost management and Hong Kong privacy expectations.
For rollout order, see our AI implementation roadmap.
Section 1
Why production AI bills balloon
Per-token prices fell, but architecture still multiplies spend after go-live.
-
Multiplier 1 Multiplier 1: Prompt-driven control flow
Open-ended agent loops resend tools, schemas, and history on every turn, turning a four-step workflow into four to six full-context calls.
-
Multiplier 2 Multiplier 2: Re-reading static context
Catalogs and policies pasted into every prompt turn static knowledge into recurring rent. Long prompts can also hit higher long-context rates.
-
Multiplier 3 Multiplier 3: Output and reasoning tax
Output tokens often cost several times input tokens. Reasoning models can bill hidden thinking tokens on tasks code handles for free.
-
Multiplier 4 Multiplier 4: Silent retries and no cache
SDK retries and JSON re-parse loops double spend. Repeatable FAQ and routing questions hit the API fresh every time.
Section 2
The boundary matrix
Assign each workflow step to the cheapest layer that can own it reliably.
Litmus tests
Can a human write this as if/else logic or a query? ▾
If yes, use code. Pricing, permissions, routing on keywords, and CRM lookups belong here.
Does a 2% error rate affect money, legal commitments, or access? ▾
If yes, enforce the rule in code or require a human gate. Do not rely on prompt wording alone.
Section 3
Five production patterns
Patterns we apply when refactoring agent prototypes into code-first production workflows.
Cost levers
Five levers beyond model choice
Cheaper calls are only one path down. These cost nothing to try and are usually worth more.
- Cap output first. Output costs five times input per token at these rates. Cutting draft length from 1,200 to 400 tokens removes about $736 a month from Architecture A before you touch a model name.
- Batch the offline work. Vendor batch pricing is often around half of standard for async jobs. Right for nightly enrichment, wrong for a live chat.
- Distil once the shape is stable. When logs show one repetitive task, move approved examples into a smaller model instead of prompting the frontier model again.
- One API key per workflow. The cheapest attribution you will ever build. Spend by workflow without a metrics stack.
- Scope the cache by tenant. Semantic caching is only safe with tenant-scoped keys. Never cache personalized pricing, and never let one customer's answer reach another.
Section 4
Worked unit economics, illustrated
Ten thousand enquiries per month, four steps each: triage, lookup, draft, CRM write-back. Every figure below is derived from the assumptions, so you can check the arithmetic against your own logs.
| Tier | Uncached input | Cached input | Output |
|---|---|---|---|
| Frontier | $4.00 | $0.20 | $20.00 |
| Mid | $2.00 | $0.10 | $10.00 |
| Fast | $0.20 | $0.02 | $1.20 |
Rates recorded 24 November 2026. Re-check them at procurement; model names change faster than prices do.
Interactive
Add a step, watch the curve
A prompt chain carries every earlier step into every later call. Code does not. Drag the step count and compare the two bills.
Compare illustrative monthly model spend for a prompt chain versus a code-first hybrid at ten thousand enquiries per month.
Prompt chain, per month $856
Code-first, per month $82
Difference $774
Calls per enquiry 4.6 vs 2.7
Ten thousand enquiries per month. The prompt chain uses one frontier tier and resends 2,500 tokens of tools and history plus 900 tokens per additional step. The code-first route keeps two bounded model calls and grows only with volume, not step count. Illustrative list prices; your token counts will differ and the shape will not.
Same model without JavaScript
| Steps | Chain per enquiry | Chain per month | Code-first per month |
|---|---|---|---|
| 1 | $0.016 | $160 | $82 |
| 2 | $0.036 | $356 | $82 |
| 3 | $0.059 | $588 | $82 |
| 4 | $0.086 | $856 | $82 |
| 5 | $0.116 | $1,160 | $82 |
| 6 | $0.150 | $1,500 | $82 |
| 7 | $0.188 | $1,876 | $82 |
| 8 | $0.229 | $2,288 | $82 |
| 9 | $0.274 | $2,736 | $82 |
| 10 | $0.322 | $3,220 | $82 |
| Line item | Volume per month | Rate | Cost |
|---|---|---|---|
| Model calls | 46,000 | 4.6 per enquiry | — |
| Uncached input | 368M tokens | $4.00 per 1M | $1,472 |
| Output | 55.2M tokens | $20.00 per 1M | $1,104 |
| Total | $2,576 | ||
| Per enquiry | $0.26 |
About 70 percent of that input is a stable prefix, so prompt caching helps. At a 60 percent cache hit the month falls from $2,576 to roughly $1,740. The band on the comparison cards reflects how often retries and growing history defeat the cache.
| Step | Handled by | Tokens in / out | Cost |
|---|---|---|---|
| Triage, 35% of enquiries | Rules and FAQ cache | 0 / 0 | $0 |
| Triage, 65% | Fast tier, 900 in, 120 out | 5.85M / 0.78M | $2 |
| Catalog and CRM lookup | SQL | 0 / 0 | $0 |
| Draft, 40% of drafts | Fast tier, 2,500 in, 700 out | 10.0M / 2.80M | $5 |
| Draft, 60% of drafts | Mid tier, 2,500 in, 700 out | 15.0M / 4.20M | $72 |
| Verification gate | Fast tier, 600 in, 100 out | 6.0M / 1.0M | $2 |
| CRM write-back | Application code | 0 / 0 | $0 |
| Total | 36.85M / 8.78M | $82 | |
| Per enquiry | $0.008 |
| Cost line | Architecture A | Architecture B |
|---|---|---|
| Model inference | $2,576 | $82 |
| Human review, 4 min per exception | 25% rate, $3,205 | 10% rate, $1,282 |
| Workflow maintenance | $200 | $400 |
| Total | $5,981 | $1,764 |
| Per resolved enquiry | $0.60 | $0.18 |
Architecture A
LLM-first agent loop
~4.6 calls per enquiry with full-context retries (46,000 calls/month at 10k enquiries).
- Each call averages ~8,000 uncached input tokens and ~1,200 output tokens.
- Agent chooses tools and reformats data on every turn.
- Spend scales with thread length and retry storms.
Illustrative monthly model spend $1.7k to $2.6k
Architecture B
Code-first hybrid
Rules, SQL, and validators absorb repeatable steps; models draft only where language is needed.
- 35% of triage exits with zero LLM tokens via rules and FAQ cache.
- Catalog and CRM steps are code-only; drafting splits 40% fast, 60% mid tier.
- A verification gate runs after drafting; failures go to a human queue, not a bigger model.
Illustrative monthly model spend $70 to $120
Section 5
Proving quality did not drop
A cheaper workflow that fails more often is not cheaper. Fix the baseline before you downgrade a single call.
| Gate | Measure | Fail action |
|---|---|---|
| Routing and intent | 95% or better on a 60 to 100 case golden set | Stay on the previous model for that step |
| Extraction | 98% exact match on money, SKU, and date fields | Fail closed to human review |
| Draft acceptance | 70% accepted without edits by a reviewer | Keep the mid tier for that step |
| Latency | p95 within the original target | Cut context and retries first, not the tier |
| Drift | Golden set re-run monthly and after every rule promotion | Revert the promotion |
Move 10 percent of live traffic to the new route for one week. Write the rollback threshold down before you start, not after the first complaint.
Then replay historical cases through both routes, including Traditional Chinese, Simplified Chinese, and mixed Cantonese and English input. A route that only passes English is not a route you can ship in Hong Kong.
Section 6
Governance, security, and Hong Kong context
Cost starts the review. Risk keeps software in production.
| Risk | What goes wrong | Code-first mitigation |
|---|---|---|
| Unbounded consumption | One loop, retry storm, or oversized prompt drains the month's budget | Step and token budgets per workflow, spend caps, concurrency limits |
| Improper output handling | Model output reaches a database or a customer unvalidated | Schema validation and reconciliation before any write |
| Sensitive information disclosure | Prompts carry more personal data than the task needs | Pre-call redaction, minimal context, tenant-scoped retrieval |
| Prompt injection | Untrusted text overrides instructions | Segregate untrusted input, validate outputs, no tool access on untrusted paths |
| Excessive agency | Broad tools turn one bad completion into an incident | Least-privilege APIs, human approval on high-impact writes |
Hong Kong PCPD guidance (2024 framework, 2025 GenAI employee checklist) emphasizes data minimization, proportionate human oversight, and clear governance. Pre-inference redaction and code-enforced approval queues support those goals in software.
Tokens are not characters. Traditional Chinese and mixed Cantonese input carry the same meaning in more tokens than English does. A Cantonese-heavy flow costs more per enquiry than an English benchmark at identical rates. Measure tokens per enquiry from your own logs before you compare vendor quotes, and budget above the slider's English-shaped curve.
Keyword routers assume one language. Hong Kong enquiries mix Cantonese particles, English product names, and Simplified Chinese copy inside the same message. Treat a regex fast path as a first pass and send low-confidence matches to the fast model, not to a code path that quietly misroutes them.
Operational guidance only, not legal advice. Consult qualified counsel for PDPO obligations and sector rules.
Section 7
Fourteen-day audit checklist
Run this diagnostic on one high-volume workflow without halting operations.
-
Instrument
- Log model ID, token counts, retries, workflow_id, and step_name on every call.
- Rank steps by monthly dollar spend, not call count alone.
-
Classify waste
- Sample 100 runs from the top-spend step.
- Tag arithmetic, lookup, formatting, and fixed routing calls.
- Measure repeat rate and retry rate.
-
Ship boundaries
- Add a deterministic gatekeeper and FAQ or SQL cache.
- Enable prompt caching on stable prefixes; cap retries.
- Route offline jobs to batch APIs where appropriate.
-
Verify and own
- Replay historical cases, including bilingual inputs.
- Compare cost per task, p95 latency, and human exception rate.
- Document the weekly spend owner.
FAQ
Questions operators ask
When should a workflow use code instead of a model? ▾
When a person could write the rule as a query or an if statement, and when a small error rate would affect money, access, or a legal commitment. Pricing, permissions, routing on keywords, and system-of-record lookups belong in code. Models handle messy input, ambiguity, and drafting.
Does moving work into code reduce answer quality? ▾
Not if the boundary sits at language rather than at convenience. Quality drops when a rule is used to fake a judgment call, or when a model is left to do arithmetic and access checks it cannot verify. Rules handle what is known and testable; models handle what is messy.
What does an LLM-first workflow cost per enquiry? ▾
In the worked example, $0.26 in model spend and $0.60 once human review is included, at 10,000 enquiries a month. The code-first version lands near $0.008 in model spend and $0.18 all-in. Token counts differ by workflow; the ratio between the two columns is the part that travels.
What is the fastest way to cut AI spend? ▾
Instrument every call with model ID, token counts, and a workflow identifier. Teams usually find a duplicate call path, an uncapped retry, or a missing cache within the first week of real traffic.
Is any of this specific to Hong Kong? ▾
The engineering is general. Three things are local: Chinese and mixed Cantonese input carries more tokens per unit of meaning than English, enquiries code-switch mid-message, and PCPD guidance expects data minimization and proportionate human oversight.
Section 8
Next step
Reducing production AI spend requires a clear boundary between deterministic code and model judgment, plus operators who verify outputs daily.
The Digiter Studio works with Hong Kong SMEs on software you own, AI inside existing systems, and governance for AI already live. Engagements start with Phase 1 (Understand) with workflow map, data boundaries, and spend visibility in writing. Where your contract includes it, our Walkaway guarantee lets you stop after Phase 1 or Phase 2 with deliverables in hand.
Ready to benchmark one workflow? Contact us or explore tailored AI services .
References
Sources
- OpenAI API documentation: Pricing and Batch API. platform.openai.com/docs/pricing
- Google Gemini API documentation: Pricing and rate limits. ai.google.dev/gemini-api/docs/pricing
- Anthropic API documentation: Pricing and prompt caching. docs.anthropic.com
- OWASP Gen AI Security Project: Top 10 for LLM Applications (2025). genai.owasp.org/llm-top-10
- Hong Kong PCPD: Artificial Intelligence Model Personal Data Protection Framework (2024) and GenAI employee checklist (2025). pcpd.org.hk