How to Integrate LLMs into Existing Products: 7 Lessons
Integrating LLMs into production apps is nothing like the demos. Here's what I learned shipping LLM features to real users, mistakes included.

A month into my LLM integration journey, I've learned enough to be dangerous and enough to be useful. I've integrated OpenAI's models into two production products so far, and the gap between "cool demo" and "production-ready feature" is wider than most people realize. Here is what I've learned, distilled into practical advice for anyone walking the same path.
Start With the User Problem, Not the Technology
This sounds like generic startup advice, but it's especially important with LLMs because the technology is so impressive in isolation. It is easy to think "I should add AI to this" without asking "what problem does this solve for my user?"
When I started integrating LLMs into ClickAi, I brainstormed a list of twenty possible features. AI-generated website copy. AI-powered design suggestions. AI chat support. AI content optimization. AI SEO recommendations. The list went on.
Then I talked to users. The number one pain point wasn't design or SEO. It was the blank page problem. Users would sign up, see an empty website builder, and freeze. They didn't know what to write. They didn't know how to describe their business. The AI feature that mattered most wasn't the flashiest one -- it was the one that helped people get past that first blank page.
So that's where I started. A simple feature: describe your business in one sentence, and the LLM generates your entire first draft of website content. Not perfect content. Not final content. Just a starting point that breaks the paralysis. Usage data confirmed the bet. Completion rates for new users jumped significantly.
The Architecture That Works
After trying several approaches, I've settled on a pattern that works well for Next.js applications integrating LLMs.
API Routes as LLM Gateways. Every LLM call goes through a dedicated API route. Never call the OpenAI API directly from the client. This gives you a single place to handle authentication, rate limiting, caching, and error handling. It also means you can swap out the underlying model without touching any frontend code.
Streaming for Long Responses. For any response that takes more than a couple of seconds, use streaming. The OpenAI API supports server-sent events, and Next.js API routes can stream responses. The perceived performance difference is dramatic. Users see text appearing word by word instead of staring at a spinner for ten seconds.
Queue for Non-Critical Tasks. Not every LLM feature needs to be synchronous. When a user publishes a website on ClickAi, I queue a background job that uses the LLM to generate SEO metadata, alt text for images, and social media descriptions. The user doesn't wait for any of this. It happens in the background and is ready when they need it.
Fallback to Deterministic Defaults. Every LLM call has a fallback. If the API is down, if the response is malformed, if the latency exceeds a threshold -- the system falls back to a deterministic default. For ClickAi, this means template-based content. For Aviation Infinity, this means pre-written explanations. Users should never see an error because your AI provider is having a bad day.
Prompt Engineering is Software Engineering
I initially treated prompts as strings. I'd hardcode them in the API route, tweak them when the output wasn't right, and move on. This doesn't scale.
Prompts are code. They should be versioned, tested, and managed with the same rigor as any other code. Here is the system I've landed on:
Prompt Templates with Variables. Every prompt is a template stored in its own file. Variables are injected at runtime. This makes prompts easy to find, easy to review in pull requests, and easy to A/B test.
System Messages for Persona. The system message defines the persona and constraints. For Aviation Infinity, the system message specifies that the AI is a flight instructor, that it should use ICAO terminology, and that it must never provide information that contradicts the official exam syllabus. This system message rarely changes.
Few-Shot Examples for Consistency. Including two or three examples of ideal output in the prompt dramatically improves consistency. For ClickAi's content generation, I include examples of good website copy for similar industries. This costs more tokens but the quality improvement is worth it.
Output Format Instructions. Always specify the expected output format explicitly. If you want JSON, say you want JSON and provide the schema. If you want markdown, say you want markdown. Never assume the model will guess your preferred format.
Cost Management is Non-Negotiable
LLM API costs can spiral out of control fast. Here is my approach to keeping them manageable.
Token Budgets Per Feature. Every feature has a maximum token budget. If a prompt plus response exceeds the budget, the request is rejected gracefully. This prevents runaway costs from adversarial inputs or edge cases.
Model Selection Per Use Case. Not every feature needs GPT-4. Most of my production features use GPT-3.5-turbo, which is significantly cheaper and faster. I reserve GPT-4 for features where the quality difference is noticeable to users, like generating detailed pilot exam explanations.
Aggressive Caching. I cache LLM responses keyed on normalized prompt hashes. If two users ask for website content for "Italian restaurant in London," they get the same cached response (with minor personalization applied after). Cache hit rates vary by feature, but even 30% cache hits make a meaningful difference to the monthly bill.
Usage Analytics. I track every LLM call: model used, tokens consumed, latency, cache hit/miss, feature that triggered it. I review these metrics weekly. This has caught bugs (a prompt that accidentally included unnecessary context, inflating token usage by 3x) and informed optimization decisions.
Testing LLM Features is Hard
Traditional testing doesn't work well for LLM-powered features because the output is non-deterministic. Here is what I do instead.
Constraint Testing. Instead of asserting exact output, I test constraints. Does the response contain required keywords? Is it under the maximum length? Does it match the expected format? Is it in the correct language?
Evaluation Sets. For critical features, I maintain a set of input-output pairs that represent acceptable quality. I run these periodically and flag any regressions. This isn't automated testing in the traditional sense -- it requires human review -- but it catches quality degradation early.
Shadow Mode. Before rolling out an LLM feature to all users, I run it in shadow mode. The existing feature continues to serve users, but the LLM version runs in parallel and logs its output. I review the shadow output for a week before switching over.
The Mistakes I Am Still Making
I am still figuring this out. A few things I know I am getting wrong:
I am probably over-engineering my prompt management system for the current scale of my products. But I've been burned enough times by "simple" systems that grow unwieldy to justify the upfront investment.
I am not doing enough evaluation. My evaluation sets are small and biased toward happy-path inputs. I need to invest more in adversarial testing and edge cases.
I am too dependent on OpenAI. If their API goes down or their pricing changes dramatically, I have a problem. I need to explore open-source models and build abstraction layers that make it easy to swap providers.
The Bottom Line
Integrating LLMs into existing products isn't as simple as adding an API call. It requires rethinking architecture, investing in prompt engineering, building solid fallbacks, and managing costs carefully. But when done well, LLMs can transform a good product into something genuinely magical for users.
The key insight is that LLMs are a new primitive, like databases or APIs. They aren't a product by themselves. They are an ingredient. The product is still the experience you build around them, the problems you solve, and the trust you earn from your users. The LLM just gives you a more powerful set of tools to work with.
Enjoyed this article?
I write about building products, AI, aviation, and the journey of entrepreneurship. Follow along for more.
Keep reading

LegalAgento: AI-Powered Unbundled Legal Services Marketplace
80% of Americans with civil legal problems can't afford an attorney. Unbundled legal services is the solution the industry ignored. We built the AI marketplace.

Prototyping LegalAgento: From Research to Working Product
How eight months of research became a working prototype. the technical decisions, the surprising challenges, and the first user reactions to AI-guided legal help.

The Future of Unbundled Legal Services: LegalAgento Bet
The legal industry is where healthcare was twenty years ago. Unbundled services powered by AI are the path to making legal help affordable.