DipzSpell
◂ ALL POSTS
· 1 MIN READ · #ai · #pathfinder

Not spending an API call per visitor

PathFinder turns "I want to be a CA" into a step-by-step roadmap, generated with the Gemini API. The obvious version calls the API for every visitor. That is slow, and on a free key it runs out fast.

So there are two cache layers.

Layer 1: a seed file

seed.json ships with the site and holds 48 pre-generated results: the 20 most searched careers, every class and interest combo, and 10 common comparisons. Most visitors get their answer from this file and never touch the API.

Searches are case-insensitive, so "Doctor", "doctor" and "DOCTOR" all hit the same entry.

Layer 2: the visitor's browser

Whatever you generate yourself is saved in localStorage for 30 days, up to 80 results. Searching the same thing again is instant.

The seed expires itself

Exam dates and cutoffs change every year, and a stale roadmap is worse than a slow one. So the seed carries its own date, and once it is more than six months old the app stops using it and goes back to live results. Re-running npm run seed before each admission season refreshes it.

Treat AI output as untrusted

The model returns JSON, but not always perfect JSON. A small normalize.js cleans and fills every response before it reaches the screen, so a missing field never breaks the page.

Validate what the model gives you the same way you would validate a form a stranger filled in.

The next step is moving the Gemini call behind a small serverless function, so the API key never reaches the browser at all.