Inflation Calculator Template
- Next.js
- TypeScript
What a past dollar is worth today, how much prices rose, and the latest US inflation rate.
A Next.js app that compares prices across time with US Consumer Price Index data. Pick an amount and a month in the past to see what it's worth in today's dollars, how much prices rose in total and per year, and the latest 12-month inflation figure. Use it on a personal finance or history site, or lift the route to adjust old prices in your own data.

What it does
- Then and now
- Turns any amount from a past month into today's dollars using the ratio of the two CPI values.
- Yearly rate
- Works out the compound yearly inflation between the two months, as well as the total rise.
- Inflation right now
- Shows the latest 12-month change; paid plans add food, housing, gasoline, medical and more.
- Cached by month
- Past months are cached for 30 days and the latest for 12 hours, so repeat questions cost nothing.
- Keeps your key private
- The browser only talks to your own API route, which holds the key, checks the date and limits each visitor to 10 a minute.
How it works
The route: it fetches CPI for the chosen month and the latest month, from the cache when it can.
/** One month of US CPI, from the cache when we have it. */
async function cpi(date: string | null): Promise<Cpi> {
const key = `cpi:${date ?? 'latest'}`;
const hit = fromCache<Cpi>(key, date ? PAST_TTL_MS : LATEST_TTL_MS);
if (hit) return hit;
const data = await callApi<Cpi>('cpiinflation', date ? { query: { date } } : {});
toCache(key, data);
return data;
}
/** GET /api/inflation?date=YYYY-MM: CPI for that month and the latest month, to compare prices across time. */
export async function GET(request: Request) {
const date = new URL(request.url).searchParams.get('date') || '';
if (!/^(19|20)\d\d-(0[1-9]|1[0-2])$/.test(date)) return fail('Pick a year and month');
const cached = fromCache(`pair:${date}`, LATEST_TTL_MS);
if (cached) return Response.json(cached);
const blocked = guard(request);
if (blocked) return blocked;
return respond(async () => {
const [then, now] = await Promise.all([cpi(date), cpi(null)]);
const data = { then, now };
toCache(`pair:${date}`, data);
return data;
});
}Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the CPI Inflation API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"yearMonth": "2026-08",
"year": 2026,
"month": 8,
"category": "food",
"index": 350.418,
"yearOverYearChange": 2.67
}
}