# Making a Nano Model Do a Flagship's Job

> A true case study from my lunch bot: how code checks, five cheap candidates and free map data let gpt-5.4-nano replace a flagship model.

- Author: Tai Pham Phu
- Published: 30 Nov 2026
- Tags: AI Engineering, LLM, Cost, Case Study, Applied AI
- URL: https://phamphutai.com/2026/11/30/making-a-nano-model-do-a-flagships-job/

My coworkers have a lunch bot. I built it as a side project, and in the third week of November 2026 they started complaining about it.

The bot is called "Bot Ăn Gì Nè", roughly "So What Do We Eat?". It lives in our group chat on Zalo, a Vietnamese messaging app. At 11:00 every weekday it suggests three dishes, each with a real quán nearby (a quán is a small local eatery, the kind with plastic stools and one thing on the menu that it does very well). People can @mention it to ask for something specific or just to chat, and it reads the last few group messages so it knows what everyone is talking about.

The complaints were fair. The bot kept making jokes about deadlines, and other worn-out office clichés. Someone asked it for a greeting that rhymed, and what came back didn't rhyme. Worse, the bot then commented on its own joke.

This post is the story of fixing that over three days, Nov 18 to 20. Halfway through, my OpenAI credit ran out and I made a rule for myself: **nano models only, no flagships, because flagships burn money.** So the real question became: how do you make the smallest, cheapest model do work that only the big model was doing well?

The short answer: you stop asking the model to do the parts it can't do, and you move those parts into code.

---

## The setup

The bot runs on a **Cloudflare Worker**, a small function on Cloudflare's servers, woken by a cron schedule for the 11:00 message and by a webhook for every @mention. It stores dish history, quán and caches in **D1**, Cloudflare's small SQLite database. It calls OpenAI's Responses API with a JSON schema, so replies come back as structured data.

The constraint that shaped everything: **each webhook has roughly 25 seconds** before it gets cut off. Anything slower than about 20 seconds is a failure, not a slow success.

---

## Why the bot kept saying "deadline"

Before changing anything, I read the prompt the way the model reads it. Three causes stood out.

**1. The persona primed it.** The system prompt described the bot as a member of "a Zalo group of coworkers". And the example replies, meant to show the tone, were office jokes: one about salary, one about the office Wi-Fi. A model learns more from examples than from instructions. I had shown it that office jokes were the house style.

**2. It was copying itself.** The bot reads recent group messages for context: up to 12 messages from the last 6 hours. Those messages include the bot's own earlier replies. So every deadline joke it made went back into the next prompt as context, and the model, seeing that this is how "the bot" talks, made another one. A feedback loop, built by me.

**3. Nothing asked for variety.** No rule said "don't repeat yourself". From the model's point of view, repeating a joke that fits is a perfectly good answer.

The poem problem had its own causes. The prompt capped every reply at 1 to 2 sentences, about 35 words. That leaves no room for a poem. And there were no rhyme rules at all, so "a greeting that rhymes" meant whatever the model guessed.

None of these were model failures. They were prompt failures. That's worth saying out loud, because the first instinct when an AI feature misbehaves is to reach for a bigger model.

---

## First fix: better instructions, bigger model

My first round was all prompt work.

- **A ban list.** The prompt now listed the stale jokes (deadline, boss, salary, meetings, overtime, KPI, Wi-Fi, Mondays) and said not to use them unless the person brought them up first.
- **Show the bot its own last 5 replies,** with an instruction not to repeat their ideas, keywords, openings or style of joke.
- **Real poem rules.** Vietnamese has a traditional verse form called **lục bát** ("six-eight"). Lines alternate between 6 and 8 syllables. The 6th syllable of the 6-line rhymes with the 6th syllable of the 8-line that follows. The 8th syllable of that 8-line rhymes with the 6th syllable of the next 6-line. And the rhyming syllables use level tones. (Vietnamese has six tones. Two of them, the flat tone and the falling tone, count as "level" in poetry; the others are "sharp".)

The chat model at that point was gpt-5.4-mini. With the new rules, it still wrote poem lines that didn't rhyme. When I raised its reasoning effort to high, the poems took over 20 seconds and timed out.

So I tried the flagship, gpt-5.5, at low effort. It wrote correct lục bát in 6 to 9 seconds. One example, with a coworker's one-syllable name taken out:

> *[Name] mê trà sữa quá ngon*
> *Trân châu lăn lóc, ví còn buồn hơn*

Roughly: "[Name] is hooked on milk tea, it's that good / The pearls roll around, and the wallet is sadder still." Six syllables, then eight. "Ngon" and "còn" rhyme, both on level tones. It's a real poem, and a funny one.

Problem solved. Then the credit ran out.

---

## The rule: nano only

From then on, I set a rule: every call uses **gpt-5.4-nano**. No mini, no flagship. A lunch bot for one office is not worth flagship prices.

The price gap is large. At the time of writing (November 2026), OpenAI's official pricing per 1 million tokens was:

| Model | Input | Cached input | Output |
|---|---|---|---|
| gpt-5.4-nano | $0.20 | $0.02 | $1.25 |
| gpt-5.4-mini | $0.75 | $0.075 | $4.50 |
| gpt-5.5 | $5.00 | $0.50 | $30.00 |

A **token** is a chunk of text, roughly a short word or part of a word. **Input** is what you send, **output** is what the model writes back, and **cached input** is input the provider has seen recently and can reuse at a discount. Per token, gpt-5.5 costs 25 times more than nano for input and 24 times more for output.

Then I tested nano with the same prompt. It was bad.

- **It ignored the ban list.** It still said "deadline". Once it wrote "Wi‑Fi" with a non-breaking hyphen, a different character that looks identical, so my simple check for "Wi-Fi" didn't catch it.
- **Its poems broke the rules.** It rhymed a word with itself ("vui ... vui", "happy ... happy"). It wrote lines with the wrong number of syllables.

I also measured one poem call properly, because the numbers surprised me.

| One poem call on nano | Effort low | Effort none |
|---|---|---|
| Input tokens | 1,394 | about the same |
| Output tokens | 1,384 | 94 |
| ...of which reasoning | 1,308 | 0 |
| Time | 13.5 s | 2.9 s |
| Did it rhyme? | No | No |

**Reasoning effort** is a setting on OpenAI's reasoning models. Higher effort means the model "thinks" more before answering, and that thinking is made of **reasoning tokens**. You never see them, but OpenAI's docs are clear that they are billed as output tokens.

Look at the low-effort column. 1,308 of 1,384 output tokens, about 94%, were thinking. At nano prices that one call cost about $0.0020, roughly five times the effort-none call (about $0.0004), took more than four times as long, and the poem still didn't rhyme. The model was paying to think and the thinking wasn't helping.

That was the turning point. **Nano can't count syllables or hear rhyme, and asking it to think harder doesn't change that.** So I stopped asking.

---

## Fix 1: a poem checker in TypeScript

If the model can't check its own poem, code can. Lục bát has precise rules, and precise rules are what code is good at.

**Syllables** are almost free: Vietnamese puts a space between every syllable, so you lowercase, strip punctuation and split on spaces.

**Rhyme** means two syllables share the same ending after the first consonant (the "rime"). "Ngon" and "còn" both end in "on". So the code removes the tone mark, then the initial consonant cluster:

```ts
const TONES = /[\u0300\u0301\u0303\u0309\u0323]/g; // the 5 tone marks
const INITIALS = ["ngh", "ng", "nh", "ch", "gh", "gi", "kh", "ph", "th", "tr", "qu", "b", "c", /* ... */];

export function rime(syl: string): string {
  const bare = syl.normalize("NFD").replace(TONES, "").normalize("NFC").toLowerCase();
  const init = INITIALS.find((i) => bare.startsWith(i) && bare.length > i.length);
  return init ? bare.slice(init.length) || bare : bare;
}
```

The trick is Unicode normalization. `NFD` splits a letter like "ồ" into a base letter plus separate accent marks, so the tone marks come off with a simple pattern. Longer clusters come first in the list, so "ngh" is tried before "ng". **Tone** uses the same trick: a level-tone syllable has no tone mark, or only the falling-tone mark.

Then the code counts **faults**: one per syllable too many or too few, one per missing rhyme (a word "rhyming" with itself counts as missing). A perfect lục bát scores 0; anything that isn't 6/8 line pairs scores infinity. A looser fallback accepts a clean rhyming couplet (two or four lines whose last words rhyme in pairs) as one fault.

### Generate five, keep the best

Now the model's job is smaller: write candidates. The checker's job is to judge them.

One call asks nano for **five different poems** in one JSON array, at effort none. Five candidates in one call cost far less than five calls, because the long prompt is sent once. The code scores all five and keeps the one with the fewest faults.

```ts
for (let round = 0; round < 2 && (best?.faults ?? Infinity) > 1; round++) {
  const out = await callOpenAI({ model, input: ask, effort: "none", timeoutMs: 7_000, /* ... */ });
  const pick = bestPoem(parsePoems(out).filter((p) => !STALE_JOKE.test(p)));
  if (pick && pick.faults < (best?.faults ?? Infinity)) best = pick;
}
return best && best.faults <= 2 ? best.poem : null;
```

At most two rounds. If the best poem has 2 faults or fewer, it goes out. If not, the bot gives up on the poem and sends a quick plain reply instead, so the whole thing stays inside the webhook budget.

This pattern has a name in the research world (best-of-n sampling), but you don't need the name. **When you can check an answer cheaply, generating several cheap answers and checking them beats paying one expensive model to get it right first time.**

---

## Fix 2: catch stale jokes in code

The ban list in the prompt didn't work on nano. So the ban moved into a regular expression:

```ts
export const STALE_JOKE = /deadline|\bsếp\b|\blương\b|\bhọp\b|\bOT\b|\bKPI\b|wi.?fi|thứ hai/iu;

export const staleJoke = (reply: string, question: string) =>
  STALE_JOKE.test(reply) && !STALE_JOKE.test(question);
```

Note `wi.?fi`: "wi", any one character or none, then "fi". That catches the non-breaking-hyphen version too. And a stale joke only counts if **the person didn't bring it up**. If someone writes "the deadline is killing me, what should I eat?", the bot may mention the deadline. It's only banned as a reflex.

When a reply fails the check:

- **One rewrite.** The bot calls nano again, saying the draft used a banned joke. A clean rewrite replaces the first answer; otherwise the first answer stays. (In the next version this gets cheaper: one call returns three differently styled replies and code scores them, penalising stale jokes, assistant phrases like "If you'd like..." and word pairs the bot used recently.)
- **Clean the context.** Old bot messages that contain a stale joke are dropped from the context before the prompt is built. This is the fix for cause #2 above. The model can't copy a joke it never sees.

That second step is easy to miss. I'd been treating the context as neutral information. It isn't. **Everything in the prompt is an example**, whether you meant it as one or not.

---

## Fix 3 and 4: less thinking, and the cache

**Chat effort from medium to low.** Chat replies need to be short, on topic and fresh, not deeply reasoned, and code now checks the freshness. Fewer reasoning tokens means lower cost and faster replies.

**A prompt cache key.** Every chat prompt starts with the same ~1,400 tokens: persona, rules, examples. OpenAI can cache a repeated prefix and bill it at the cached price, $0.02 per million instead of $0.20. Its docs say the prefix must match exactly, and that `prompt_cache_key` helps route related requests to the same cache without guaranteeing a hit. So the static part goes first, the changing part (recent messages, weather, the question) last, with the same key on every call.

**Honest status: I haven't confirmed it works.** In my test calls, `cached_tokens` was 0 every time. For models before GPT-5.6, OpenAI's docs say the minimum cacheable length depends on request settings such as the output schema and reasoning effort, so my prefix may simply be too short. The saving would be tiny anyway, about $0.00025 per call. I left it in because it costs nothing.

---

## The results

After these changes, with nano only:

- **Plain replies:** about 3 seconds. In my test runs, no stale jokes got through.
- **Poems:** 5 to 11 seconds. They're passable, not great. They have the right shape and usually rhyme, but they're not as funny as the flagship's. One I got back opened with a coworker admiring the sunshine out on the porch, which is a correct lục bát line and not much of a joke.

That's the honest trade. The flagship was a better poet. Nano plus a checker is a good-enough poet, at a fraction of the cost, and a poem request is rare. For a lunch bot, good enough is the right target.

---

## The real cost was somewhere else

With the model problem fixed, I estimated what each kind of request costs. This is where the story turned.

At nano prices, **a normal chat reply comes to roughly $0.0005 to $0.0007.** Less than a tenth of a US cent.

But when someone asks for food, the bot also looks up a real quán nearby. At that point the lookup used OpenAI's **web search tool**. At the time of writing, that costs **$10 per 1,000 calls**, plus the retrieved search text billed as tokens at the model's rate.

A typical lookup did about 3 searches. That's 3 × $0.01 = $0.03 just in search fees, before any tokens.

| Request | Rough cost |
|---|---|
| One chat reply (nano) | $0.0005 to $0.0007 |
| One quán lookup (~3 web searches) | ~$0.03 |

$0.03 divided by $0.0006 is 50. **One quán lookup cost about as much as 50 chat replies.** I had spent two days squeezing the model, and the model wasn't the expensive part. The tool call was.

For the full breakdown of where money goes in a model call (input, output, reasoning, caching, tools), see [What an LLM Call Really Costs](https://phamphutai.com/2026/11/30/what-an-llm-call-really-costs/).

---

## Free data first

So the quán lookup got its own fix: try the free sources first, and only pay when they all miss. A lookup ladder, cheapest rung first.

1. **Quán the group added themselves.** A `/themquan` command ("add quán") lets anyone save a place: dish, name, address. These never expire, because a recommendation from a coworker is the best data the bot has.
2. **Quán found in the last 90 days.** Every quán the bot found before is stored in D1. Recent ones are reused. Older ones expire, because quán close and move.
3. **OpenStreetMap.** OpenStreetMap (OSM) is the free, community-built map of the world. Its **Overpass API** is a public, read-only service that answers questions like "every named restaurant, café or food stall within 1.5 km of this point". For our office, that came back with 455 named places. The list is cached per office for a week.
4. **Paid web search,** only when all three miss.

Public Overpass servers often reply that they're "at capacity", and the OSM wiki itself says reliability isn't guaranteed. So the code tries three public servers in turn, and if all fail, it uses the stale list. An old list of real places beats no list.

### Matching dishes to names is harder than it looks

OSM has names and sometimes a cuisine tag, not menus. The bot has to guess from the name.

My first version matched 39 of 87 dishes on the bot's menu. That looked great until I read the matches:

- **Fried seafood rice** matched a craft beer bar, because the bar was tagged "seafood".
- **Bún chả** (the Hà Nội grilled pork noodle dish) matched a shop selling **bún chả cá**, a completely different fish-cake noodle soup that happens to contain the same two words.
- **Cơm Ấn** (Indian rice) matched a vegetarian rice shop, because the only word that matched was "cơm", which just means "rice".

The fixes were all small rules:

- **All the dish's words must appear in the name.** Not just one.
- **Drop place names from the dish.** "Cơm gà Hội An" (Hội An chicken rice) rarely has "Hội An" in the quán's name.
- **Ignore generic one-word matches.** "Cơm", "bún", "phở" on their own match half the city.
- **Trust cuisine tags only where the tag is specific.** A "bubble_tea" tag can vouch for milk tea. A "seafood" tag can't vouch for fried seafood rice.
- **One special case:** "bún chả" must not match "bún chả cá".

After that: **27 of 87 dishes matched, and the matches were clean.** Fewer matches, all of them right. For a feature where a wrong answer sends hungry people to a beer bar, that's the better number.

<figure class="diagram">
<svg viewBox="0 0 680 340" role="img" aria-label="Lookup ladder from cheapest to most expensive: quán the group added, quán found in the last 90 days, OpenStreetMap via Overpass, and paid web search only when all three miss." xmlns="http://www.w3.org/2000/svg">
<defs><marker id="arrow-nano-ladder" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="currentColor"/></marker></defs>
<text x="20" y="22" font-size="12" class="muted">cheapest first; stop at the first hit</text>
<rect x="20" y="35" width="430" height="50" rx="6" fill="none" stroke="currentColor" stroke-width="1.5"/>
<text x="35" y="57" font-size="13">1. Quán the group added (/themquan)</text>
<text x="35" y="75" font-size="12" class="muted">free, never expire</text>
<line x1="235" y1="85" x2="235" y2="112" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<text x="245" y="103" font-size="11" class="muted">miss</text>
<rect x="20" y="115" width="430" height="50" rx="6" fill="none" stroke="currentColor" stroke-width="1.5"/>
<text x="35" y="137" font-size="13">2. Quán found in the last 90 days</text>
<text x="35" y="155" font-size="12" class="muted">free, stored in D1</text>
<line x1="235" y1="165" x2="235" y2="192" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<text x="245" y="183" font-size="11" class="muted">miss</text>
<rect x="20" y="195" width="430" height="50" rx="6" fill="none" stroke="currentColor" stroke-width="1.5"/>
<text x="35" y="217" font-size="13">3. OpenStreetMap via Overpass</text>
<text x="35" y="235" font-size="12" class="muted">free, 455 places in 1.5 km, cached 1 week</text>
<line x1="235" y1="245" x2="235" y2="272" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<text x="245" y="263" font-size="11" class="muted">miss</text>
<rect x="20" y="275" width="430" height="50" rx="6" fill="currentColor"/>
<text x="35" y="297" font-size="13" class="on-fg">4. Paid web search</text>
<text x="35" y="315" font-size="12" class="on-fg">~$0.03 per lookup (~3 searches)</text>
<line x1="450" y1="60" x2="497" y2="60" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<line x1="450" y1="140" x2="497" y2="140" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<line x1="450" y1="220" x2="497" y2="220" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<line x1="450" y1="300" x2="497" y2="300" stroke="currentColor" stroke-width="1.5" marker-end="url(#arrow-nano-ladder)"/>
<text x="505" y="64" font-size="13">hit: send</text>
<text x="505" y="144" font-size="13">hit: send</text>
<text x="505" y="224" font-size="13">hit: send</text>
<text x="505" y="304" font-size="13">hit: send</text>
</svg>
<figcaption>The quán lookup ladder: three free rungs before the one that costs money.</figcaption>
</figure>

A few days later I decided to go one step further and remove the paid search rung entirely. In the next version, when all three free sources miss, the bot sends a Google Maps search link for that dish near the office and asks the group to `/themquan` the place if it turns out good. Maps link: free. Coworkers adding places: free, and better data than any search.

---

## A bug that was hiding the whole time

The OSM rung needs the office's coordinates, which come from **Nominatim**, OpenStreetMap's free geocoder (it turns an address into latitude and longitude). The bot already used it for a "too far" filter that dropped quán clearly far from the office.

Our office is in Hải Châu, Đà Nẵng, and its address starts with a building name. Nominatim never found it. The code was written so that "address not found" never removes a quán, a reasonable safety choice. The side effect: **the distance filter had never run.** Not once.

The fix tries the address again from the house number onward, then the street plus ward and district, then the street plus city. Lookups are cached and run one at a time, because Nominatim's usage policy allows at most one request per second.

The lesson: **a safe fallback can hide a broken feature forever.** "Can't check, let it through" is right for users, but log how often it happens. If it's every time, you don't have a filter.

---

## What I'd tell myself on Nov 18

**Put the rules the model can't follow into code.** If you can write a check for it, write the check. A small model plus a strict checker often beats a big model plus a polite request.

**Generate several cheap candidates, then verify.** This works whenever checking is cheaper than writing.

**Reasoning tokens are where cheap models get expensive.** Effort is a cost setting, not a free quality dial. Measure it per task.

**Measure before choosing a model.** Tokens, seconds, and "did it actually rhyme" told me more than any benchmark. [How to Evaluate an AI Feature](https://phamphutai.com/2026/11/04/evaluating-ai-features/) shows how to make that a habit.

**The tool calls can cost more than the model.** A $0.01 search fee sounds like nothing until you put it next to a $0.0006 reply.

**Free data first.** Here the free sources weren't just cheaper. A coworker's recommendation is better data than a search result.

And from the stale-jokes saga: **everything in the prompt is an example**, including the bot's own past messages.

None of this is specific to lunch bots. It's [treating the LLM like an unreliable API](https://phamphutai.com/2026/10/14/treat-the-llm-like-an-unreliable-api/): wrap it, check its output, have a fallback. And if even nano is more than a task needs, a small model on your own machine may do; see [Run AI Models on Your Laptop](https://phamphutai.com/2026/11/04/run-ai-models-on-your-laptop/).

---

## Key ideas

- Most "the model is bad" problems in this bot were prompt problems: office-joke examples, the bot re-reading its own jokes, and no room or rules for a poem.
- When a small model can't follow a rule (syllable counts, rhyme, banned topics), check the rule in code and reject or rewrite the output.
- Ask for several candidates in one call at low or no reasoning effort, score them in code, and keep the best. Always have a quick fallback that fits the time budget.
- Reasoning tokens are billed as output. On nano, effort low used 1,308 reasoning tokens on one poem, cost about five times more than effort none, and still didn't rhyme.
- A web search tool call ($10 per 1,000) made one quán lookup cost about 50 chat replies. The tools, not the model, were the real cost.
- Use free data first: user-added places, your own recent results, OpenStreetMap. Then pay only for what's left, or not at all.
- A "can't check, let it through" fallback can silently disable a feature. Log how often it fires.

*Sources: [OpenAI API pricing](https://developers.openai.com/api/docs/pricing) (gpt-5.4-nano, gpt-5.4-mini, gpt-5.5, web search tool, checked November 2026); [OpenAI prompt caching guide](https://developers.openai.com/api/docs/guides/prompt-caching); [OpenAI reasoning guide](https://developers.openai.com/api/docs/guides/reasoning) (effort levels, reasoning tokens billed as output); [Overpass API, OpenStreetMap Wiki](https://wiki.openstreetmap.org/wiki/Overpass_API); [Nominatim usage policy](https://operations.osmfoundation.org/policies/nominatim/). Token counts, timings and match counts are from my own test runs and logs, Nov 18 to 20, 2026.*

*Related: [What an LLM Call Really Costs](https://phamphutai.com/2026/11/30/what-an-llm-call-really-costs/) · [Treat the LLM Like an Unreliable API](https://phamphutai.com/2026/10/14/treat-the-llm-like-an-unreliable-api/) · [How to Evaluate an AI Feature](https://phamphutai.com/2026/11/04/evaluating-ai-features/)*
