How I built PocketTripAI: an AI trip planner that sticks to your budget
By Adarsh Raut ·

I'm Adarsh Raut, a full stack software developer based in Pune. PocketTripAI is an AI travel planner. You enter a destination, dates, travel style and a budget, and it returns a day-by-day itinerary with costs for every activity. The code is on GitHub.
Plenty of AI planners write a nice-sounding trip and ignore what you can afford. The goal here was a plan that actually fits the number you give it. It's built with Next.js 16, TypeScript, Drizzle ORM, PostgreSQL, Supabase Auth and Tailwind.

Structured output, not free text
The model doesn't write prose. It returns JSON that matches a Zod schema: days, activities with times and categories (attraction, food, transport or free), a cost for each, lodging and meal suggestions and a trip total. I generate the JSON Schema for the request from the same Zod schema I use to validate the response, so the two can't disagree.
The prompt also tells the model to use real landmarks, not to invent prices and to keep the activity costs consistent with its stated totals.
A budget check that sends the plan back
This is the part I care about most. After the model answers, a checkBudgetFit function compares the plan with your hard budget:
- the plan's stated total has to be within 5% of the per-person budget
- the itemized activities have to be within 15% of it
If the plan is over, the model gets a second prompt that includes the exact overage and tells it to cut real costs, such as cheaper lodging, street food and free attractions, not just lower the total. It can do this up to two times. If the plan still doesn't fit after that, you get the last valid plan and the dashboard shows by how much it's over.
Separately, a per-city cost model with travel-style multipliers and a 15% buffer gives a sanity baseline that goes into the prompt.
Generation that survives serverless
A good itinerary can take a while to generate, which doesn't suit a normal request on Vercel. So POST /api/trips validates the form, reserves a plan slot, saves the trip and answers "queued" in about two seconds. The actual generation continues in Next.js after() on that same request, with maxDuration set to five minutes. The client polls a plan endpoint and shows the stage: generating or revising.
Failures that clean up after themselves
Long jobs fail in messy ways: a timeout, a redeploy halfway through, a model that returns garbage. Two details keep that from costing users:
- Marking a plan failed is a database update guarded by its current status (
queuedorgenerating). Only the call that actually changes the row refunds the free-plan slot, so a slot can't be refunded twice. - If a plan has been stuck too long, the next poll fails and refunds it.
Free and Pro limits
Free users get two AI plans per month. The counter resets by comparing a stored month with the current one in a single SQL statement, and refunds never take it below zero. Pro is unlimited. Payments aren't wired up yet, so Pro currently uses a development-only upgrade path, and Razorpay is on the roadmap.
Auth and the local dev login
Production uses Supabase Auth with email and Google sign-in. Locally there's a one-click dev login so I can test without credentials. It only works when NODE_ENV is development, so it can't run in a production build.
Provider-agnostic AI
The AI layer talks to an OpenAI-compatible API, so I can switch between Gemini, Groq and a local Ollama model with an environment variable.

What I'd do next
- Currency conversion and a local phrase guide.
- Weather-aware suggestions.
- Follow-up chat on an existing plan, and live flight and hotel prices.
You can browse the Lisbon and Tokyo itineraries in the PocketTripAI demo without signing in. The samples are read-only. Sign in to generate, edit, and save your own trip. I'm happy to talk about how it works on LinkedIn.