AX notes · Series

Adding an LLM to an app: cost, cache and disclosure

Adding Gemini to a Korean spelling app, a 59-case eval picked a model at $0.93 per 1,000 calls. Four parts on that choice, a shared cache, test spending caps and where AI processing happens.

4 parts

What this series found

  • On 59 corrections, flash-lite explained 78% correctly and gemini-3.8-flash 100%, at $0.93 per 1,000 calls. The server function stops LLM calls at 3,000 a day, and in the two weeks after launch 3.7% of users who ran a check tapped "Why is this wrong?". (Part 1: cost and limits)
  • If the model sees context that the shared cache key leaves out, one user's prompt injection can become everyone's answer. In blind grading, answers without the context scored 96.6% and with it 96.0%, so we dropped it. (Part 2: cache keys and injection)
  • Our eval runner was set to stop at 2,500 KRW, yet billing showed 2,956 KRW (budget alert, October 11, 2026): its ledger only added up calls that returned a response. Now any spending path with no cap set spends nothing. (Part 3: hard caps on test spend)
  • A Vertex AI global endpoint cannot be pinned to one country. A privacy-policy line naming the Seoul region stayed public for 8 hours 55 minutes before it changed to "may be processed outside Korea"; the app had no users yet. (Part 4: disclosing AI location)

This series is for solo developers adding an LLM feature for the first time. The parts follow the real order of work: pick a model (Part 1), design the cache (Part 2), cap spending during development (Part 3), disclose processing before launch (Part 4). If the feature is already live, read Part 2 if you cache responses and Part 3 if an agent runs your evals. Part 1 also covers why all 59 eval calls first failed with HTTP 402: the AI Studio key was not tied to our cloud credit.

Checks we now run before an LLM feature ships

Each part ends with its own steps. Read together, they fall into the order below. Every check here is one we added after something went wrong in that part, not a general best practice.

  1. Make one real call through the path that bills your cloud account before writing anything else. A 402 or 403 means the billing path is wrong; in Part 1 it was an AI Studio key that never touched the free-trial credit.
  2. Confirm the model exists in the location you plan to use with countTokens, which is not billed. In Part 4 the two chosen models returned 404 in Seoul and Tokyo, and only the global endpoint answered.
  3. Pick the model with about 50 cases from your own test data, and write the pass mark before the run. Set the thinking budget of a thinking model to 0, or its thinking can use up a small output limit before any answer appears (Part 1).
  4. List the fields the model sees next to the fields in the cache key. Any field the model sees but the key leaves out is a path for one user's text to become every user's answer (Part 2). Measure whether that field helps before you keep it.
  5. Put the model name and prompt version in the cache key, so a model change never serves old answers (Part 2).
  6. Make a missing value mean no spending: a daily cap of 0 in code, a dry run unless a flag says otherwise, and a call with no token count charged at the full cap (Part 3). Count thinking tokens as output; they are billed at the output rate.
  7. Treat an eval runner's own ledger as a lower bound and check billing the next day. Ours said 1,584 KRW for the main run while the October bill reached 2,956 KRW (Part 3).
  8. Keep the processing location in one constant and have CI compare it with the in-app notice and the privacy policy. The policy should not name a location until a real call has answered there (Part 4).

These checks come from two apps, a spelling checker and a family planner, both calling Gemini models on Vertex AI for Korean users. The billing and location details are specific to Google Cloud; the cache-key and missing-value rules carry over to any provider.

Series contents

  1. Part 1The first LLM feature in a spell-check app: cost, model evaluation and daily caps for "Why is this wrong?"

    A 59-case eval picked a Gemini model at $0.93 per 1,000 calls, a 3,000-call daily cap in the function limits spend, and an AI Studio 402 moved us to Vertex AI.

  2. Part 2A shared LLM cache could have frozen a prompt injection: the blind A/B that let us stop sending context

    A shared LLM cache keyed without the context could serve one injected answer to every user.

  3. Part 3Capping Vertex AI test costs: a 2,500 KRW stop line missed a 2,956 KRW bill, so we changed the defaults

    Our evaluation runner stopped at 2,500 KRW, yet billing showed 2,956 KRW: its ledger counted only responses.

  4. Part 4Privacy policy AI processing location (cross-border transfer): a notice fixed twice in one day, then tied to code

    A Vertex AI global endpoint cannot be named as one country, so our privacy policy says processing may happen outside Korea, tied to code and CI.

All AX notes