惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园_首页
有赞技术团队
有赞技术团队
V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
# How I Built an AI Travel Planner — and What I Got Wrong
Takshil Pandya · 2026-06-24 · via DEV Community

Takshil Pandya

I built Kartografer — an AI travel planner where you describe a trip and Gemini generates a full day-wise itinerary. You can then edit it, chat with the AI for suggestions, share a public link, and export a PDF travel proposal.

Here are the decisions that mattered most.


The one rule that held everything together

Every itinerary item has one boolean: isSelected.

isSelected: true  → final plan
isSelected: false → option/suggestion

That's it. But this single field flows through the entire app. Budget only sums selected items. Public pages, share links, and PDF export only show selected items. Moving something to the options panel doesn't delete it — it just flips the flag.

Without this, I'd have needed separate tables for draft vs final content, or conditional logic scattered everywhere. One field kept it clean.


Why the AI never directly edits a trip

The obvious approach: user sends a message → AI updates the database. Simple. And completely wrong.

If the AI can directly mutate your itinerary, one bad response silently corrupts your plan. So I built a proposal flow instead:

User sends chat message
→ Gemini returns a reply + structured proposedChanges JSON
→ Proposal saved as PENDING
→ UI shows a preview card
→ User clicks Apply
→ Separate server action re-validates JSON + re-checks ownership
→ DB updates run + budget recalculated

The chat action never touches the itinerary. The apply action doesn't trust the proposal — it validates everything from scratch. Worst case: the AI returns garbage, the user sees a bad suggestion card and dismisses it. The trip stays untouched.


Long trips needed chunked generation

A 14-day itinerary is a large JSON structure. One Gemini request risks token limits and timeouts. So long trips are split into sequential chunks — a few days at a time — each validated against a Zod schema before moving to the next.

For reliability, three Gemini API keys rotate on retryable errors (429, 500, 502). One thing I got right: invalid JSON responses don't trigger key rotation. That's a content problem, not an API problem. Rotating keys on bad output just wastes quota.


PDF export — why I didn't use a library

I tried a few HTML-to-PDF libraries. The output was consistently broken — fonts missing, layouts collapsed. Most of them don't run a real browser engine, so anything depending on computed styles or custom properties breaks.

The fix was Playwright with real Chromium. The API route launches it headlessly, navigates to the export preview page, and captures it as A4. The preview page and the PDF are the same template — what you see is exactly what gets downloaded.


The free-tier wall

Kartografer runs on Gemini's free tier. Multi-key rotation helps with per-minute limits but not daily caps. At any real traffic volume, it runs out fast — and I don't have the budget to fix this with money right now.

So I've been thinking about working around it with design:

  • Cache common itineraries — Paris 7-day budget trips don't need fresh generation every time
  • Use Explore as a seed — adapt an existing published itinerary instead of generating from scratch
  • Async queue — smooth out burst traffic instead of failing mid-request
  • BYOK — let users connect their own Gemini key for unlimited personal generation

None of these are built yet. But a hard resource constraint forces you to think about AI differently — not as an unlimited utility, but as something to use carefully.


What I'd do differently

Define the AI proposal schema first. I built the chat feature before locking down what a proposal looked like. That meant refactoring the chat action later to remove direct itinerary mutations. Starting with the schema would have made the whole integration cleaner.


The full source is on GitHub. Live at kartografer.com.