Inspiration
Imali AI runs the books, stock and sales of shops, suppliers and company groups. Many merchants we build for still keep the book in a paper exercise book. A model on the device reads an entry where the signal drops, uses no data and keeps customers' names on the device, but a small model also makes mistakes with money. We wanted a book that keeps Gemini Nano's speed and privacy and never puts a wrong figure in the totals.
What it does
The owner types what happened, in their own words: "Sold 3 loaves at R15 each to Thandi, she pays Friday". Gemini Nano reads it in Chrome and returns one record: a sale on credit, 3 x R15 = R45, Thandi, Friday. Plain code then checks the record against the words. Each line must add up, the lines must make the total, a price said "each" must be a unit price, every number must come from the words, and the currency and the person must match.
When a check fails, the words go to a cloud Gemini model for a second opinion, with the failed checks attached and the names and phone numbers the app finds swapped for placeholders first. The answer comes back, the names are put back on the device, and the same checks run again. An entry that still fails is marked "Needs you" and stays out of the totals.
The owner can also photograph a supplier's receipt, which Gemini Nano reads on the device, and ask the book questions such as "Who owes me money?". Nano turns the question into a small query, and code adds up the answer from the book in the browser. The book itself never leaves the device.
Offline, everything Nano can read still works. An entry that needs the cloud waits on the device and goes for its check when the connection is back.
How we built it
Firebase AI Logic carries every model call. One getGenerativeModel call holds both engines: onDeviceParams for Gemini Nano and inCloudParams for the cloud model, with the same JSON Schema for both (Nano's responseConstraint, the cloud's responseJsonSchema). Typed entries use ONLY_ON_DEVICE first and ONLY_IN_CLOUD for the second opinion, so the names the app finds are swapped out before anything leaves. Receipt photos use PREFER_ON_DEVICE, so the SDK picks Nano when the device has it. inferenceSource on each response records where it ran, and the app shows it to the owner.
App Check is enforced for AI Logic (reCAPTCHA Enterprise on the hosted copy), so a cloud call without a valid token is refused. Each browser may make 60 cloud calls a day. The app is a React and TypeScript web app on Firebase Hosting with an offline service worker, and the book lives in IndexedDB.
Challenges we ran into
On the first day Gemini Nano read "two bags of maize meal for 120 rand each" as two bags at R60. Its sums were consistent, so a sum check alone would have passed it. That led to the checks that compare a reading with the owner's own words.
Chrome's language detector is unreliable on short messages: it called "Thandi paid R30" Hindi. So the app sends words to the cloud for their language only when the detector is sure, and tries Nano first otherwise.
Accomplishments that we're proud of
The book runs on an ordinary computer. In the recording for the video on 14 November 2026 (Chrome 157 on an eight-core computer with no graphics card, against the live Firebase project), Gemini Nano read four typed entries right on the device in 7.3 to 19 seconds, a supplier's receipt photo in 21 seconds and the question "Who owes me money?" in 4.5 seconds, and none of them left the device. When Nano read the maize meal as 2 x 60 = 120, the checks caught it and a gemini-3.6-flash second opinion gave R240, the right total, in 27 seconds. The Kiswahili entry, typed offline, waited on the device and was read in the cloud in 1.8 seconds once the connection was back, with the customer's name taken out first. At the end the book counted seven readings on the device and two in the cloud.
The cloud path holds when a model does not answer. In an earlier recording run on 14 November, gemini-3.6-flash gave nothing within its 60-second limit, so the app asked gemini-3.5-flash-lite, the maize entry still came out right, and the slip said which model answered and why. On the hosted copy on 12 November, with App Check tokens from reCAPTCHA Enterprise, all six entries were checked: four on the device, the maize meal fixed by a gemini-3.6-flash second opinion in 9.3 seconds and the Kiswahili entry read in the cloud in 10 seconds with the name removed. A cloud call without an App Check token is refused with 401.
What we learned
A small model's mistakes look right, so a check has to go back to the owner's words. A reading that only agrees with itself proves nothing.
Name removal has to judge whole words. Our first guard looked for a removed name anywhere in the prompt, so "Juma" was still "found" inside "Ijumaa", the Kiswahili word for Friday, and the entry was never sent. A test with stubbed models caught it before release.
The first runs against the real project found what the stubbed tests could not: gemini-3.8-flash on the free tier answered "high demand" or nothing for three minutes, gemini-3.5-flash-lite once wrote the customer as PERSON_1 without its brackets, and Nano wrote CFA where the words said FCFA. Each now has a test: a 60-second limit with a fallback model, a check that no placeholder is left in an answer, and the model's currency read through the same table as the words.
Gemini Nano's answers vary between runs, so every reading goes through the same checks however it was made.
What's next for Imali AI book
Next we want to link the book to an owner's Imali AI account, so an entry written in Chrome, online or offline, joins the records they already keep in Imali AI. After that comes the same device-first reading in Imali AI's Android app on phones that carry Gemini Nano, and voice notes read on the device the way typed words are, because many owners would rather say an entry than type it. Wherever the words are read, code checks every number before it reaches the totals.
Built With
- chrome-prompt-api
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- gemini-api
- gemini-nano
- indexeddb
- react
- typescript
- vite