Thomas Osayi

November 23, 2026 · 10 min read · Thomas Osayi

How to add AI to your SaaS app: practical features, server routes, costs and guardrails

How to add AI to a SaaS app: summaries, search, chat over your data and classification, server-side API calls, per-request costs at current prices, evals and guardrails.

Most founders who ask me to add AI to their SaaS app do not need a chatbot. They need one feature that saves their users ten minutes a day: a summary of a long thread, a search box that understands what people mean, a way to ask questions about their own records, or automatic tagging of whatever comes in. Those features are small, cheap to run and easy to test, which makes them a much better first step than a general assistant.

This post covers what to build first, how to call the OpenAI or Anthropic API safely from a server route, what each request costs at current prices, and how to test and guard the output. It assumes a Next.js app, but the same structure applies to any backend.

How do I add AI to my SaaS app without rebuilding it?

You add AI as one more server route that takes data your app already has, sends it to a model with clear instructions, and returns a result your interface shows next to the existing feature.

Nothing about your database, auth or billing needs to change. The pattern looks like this:

  • A button or background trigger in the existing screen, such as "Summarize this ticket".
  • A server route that checks who the user is and which records they can see.
  • A function that loads those records, builds a prompt and calls the model API.
  • A response, streamed or returned in one piece, that the screen displays.
  • A log row that stores the user, the feature, token counts and cost.

The model provider is a detail you can swap later if you keep the call in one place. I wrap the provider SDK in a single function such as summarizeTicket in a file like lib/ai.ts, so changing from one model to another is a one-line change rather than a hunt through the codebase.

If your app was built with an AI builder and is still fragile, fix the basics first. "Fix or rebuild your AI-built app? How to decide before you spend more" helps you decide whether it is ready for new features.

Which AI features are worth building first?

The best first AI features use data you already store, produce output a user can verify quickly, and replace a task people already do by hand.

Summaries

Turn a long support thread, meeting notes, an order history or a set of reviews into a few lines. The input is already in your database, and a user can tell instantly if the summary is wrong.

Search that understands meaning

Let users type "clients who missed two appointments" instead of building filters. This usually means creating embeddings for your records and storing them, often in Postgres with the pgvector extension, then letting a model rank or explain the results.

Chat over the customer's own data

Answer questions about a user's own records by retrieving the relevant rows first and passing only those to the model. The retrieval step is what keeps answers grounded and keeps one customer's data away from another.

Classification and extraction

Tag incoming emails by topic, pull fields out of uploaded documents, or flag messages that need a human. These are cheap, run in the background, and are easy to measure because there is a right answer.

How do you call the OpenAI or Anthropic API from a server route?

Call the API only from your server, using a key stored in a server-only environment variable, after you have checked the user and loaded only the data they are allowed to see.

In a Next.js App Router project, that means a route handler such as app/api/ai/summarize/route.ts or a server action. The steps inside it:

  • Read the session and reject the request with a 401 if there is no user.
  • Load the record by ID and confirm it belongs to the user's account, returning a 404 if not.
  • Build the prompt on the server. Never accept a raw prompt from the browser for a feature like this.
  • Call the provider SDK with the key from an environment variable such as ANTHROPIC_API_KEY or OPENAI_API_KEY, with no NEXT_PUBLIC prefix.
  • Set a maximum output length so a runaway response cannot cost more than you expect.
  • Stream the result for anything longer than a sentence, so the user sees progress.

Two things catch people. First, Vercel Functions have a maximum duration, 300 seconds by default at the time of writing, so long generations or large batches belong in a background job. Second, keys with a NEXT_PUBLIC prefix are bundled into the browser. "API key exposed in your frontend? Which keys are safe and how to fix the rest" covers how to fix that if it has already happened.

How much does each AI request cost?

At the time of writing, most practical SaaS AI features cost between a hundredth of a cent and about two cents per request, depending on the model and how much text you send.

Model APIs charge per million tokens, separately for input and output. A token is a small chunk of text, often part of a word, and the provider's token counter tells you exactly how many a prompt uses. Prices from the providers' pricing pages at the time of writing, for standard requests:

  • Claude Haiku 5.5: $0.10 per million input tokens and $0.50 per million output tokens, for prompts up to 100,000 tokens.
  • Claude Sonnet 5.5: $2 input and $10 output per million tokens.
  • Claude Opus 5.5: $4 input and $20 output per million tokens.
  • OpenAI gpt-6-luna: $0.10 input and $0.50 output per million tokens.
  • OpenAI gpt-6.1-terra: $1 input and $5 output per million tokens.
  • OpenAI gpt-6.2-sol: $2 input and $10 output per million tokens.
  • OpenAI text-embedding-3-small: $0.02 per million tokens, for search embeddings.

Both providers discount batch processing by half for work that does not need an instant answer, and both discount repeated prompt prefixes through caching. Anthropic also notes that Claude 4.7 and later models use a newer tokenizer that produces about 30% more tokens for the same text, so count tokens with the model you will actually use.

A worked example: costing AI for a help desk tool

As an illustration, picture a small help desk SaaS that wants two features: a summary button on long tickets and automatic tagging of every new ticket.

  • Summary: a 3,000-token ticket thread in, a 300-token summary out. On Claude Haiku 5.5 that is 3,000 times $0.10 per million plus 300 times $0.50 per million, about $0.00045. On Claude Sonnet 5.5 it is about $0.009.
  • Tagging: 500 tokens in and about 10 tokens out per ticket on gpt-6-luna, about $0.000055.
  • Volume: 5,000 summaries and 20,000 tagged tickets a month.

Monthly cost: about $2.25 for summaries on Haiku 5.5, or about $45 on Sonnet 5.5, plus about $1.10 for tagging. Even on the larger model, that is a small line next to hosting and email.

Chat over data costs more because you send more context. Retrieving 8,000 tokens of a customer's records and returning a 500-token answer on Sonnet 5.5 is about $0.021 per question, so 10,000 questions a month is about $210. That is when model choice, caching and limits start to matter.

How do you stop one user from running up your bill?

Rate limit every AI route per user and per account, cap input size, and set a spend limit in the provider's console so a bug or an abusive user cannot cost more than you planned.

The checks I put on every AI route:

  • A per-user limit, such as a set number of requests per minute and per day, stored in Redis or a database table.
  • A per-account monthly allowance that matches the customer's plan, which also gives you an upgrade path.
  • A cap on input length, trimming or rejecting anything larger than the feature needs.
  • A maximum output token setting on every call.
  • A monthly spend limit and usage alerts in the provider's console.

The providers also enforce their own rate limits, which rise as your account moves up their usage tiers. Anthropic describes Start, Build and Scale tiers on its pricing page. Handle a 429 response from the provider with a short retry and a friendly message rather than an error screen.

Logging cost per call is what turns this from guesswork into numbers. A simple ai_calls table with user, account, feature, model, input tokens, output tokens and cost lets you answer "which customer is using this most" in one query.

How do you test AI features before users see them?

Build a small set of real examples with the answers you expect, run every prompt or model change against it, and only ship changes that score at least as well as the current version.

This is what people mean by evals, and for an MVP it does not need a framework. A spreadsheet or a JSON file works:

  • Collect 30 to 50 real inputs, with customer data removed or anonymized.
  • Write down what a good output looks like for each, or the correct tag for classification.
  • Run the feature against every example and score the results, by hand for summaries and automatically for tags.
  • Keep the failures and add new ones whenever a user reports a bad answer.

Classification is the easiest to measure because each example is simply right or wrong. Summaries need a human glance, but even ten minutes of reviewing before a release catches the worst regressions. "How to add tests to an AI-generated app, and what to test first" covers testing the non-AI parts of the same app.

What guardrails does an AI feature need?

Guardrails keep the model inside the job you gave it: grounded in the user's own data, unable to reach other customers' records, and clearly labelled when it is unsure.

  • Retrieve data with the user's permissions before calling the model, so the model never sees anything the user could not see.
  • Treat text from documents, emails and web pages as data, not instructions, because it can contain text that tries to redirect the model.
  • Ask for structured output, such as JSON with fixed fields, when the result feeds other code, and validate it before saving.
  • Show sources or the records used, so users can check the answer.
  • Keep a human in the loop for anything that sends messages, changes records or touches money.
  • For health, legal or financial products, keep AI output as a draft for a professional and check your provider agreements. This is general information, not legal advice.

Should AI live inside your app, or should you connect AI to your data?

Put AI inside your app when your customers need the feature; connect an assistant such as Claude to your data when your own team needs answers.

THG Brain is an example of the second approach. It is the internal data platform I built at The Hoop Gang, and it syncs the brand's sales, email, ads, support inbox and creator portal into one place that the team can query from their own Claude. Nobody had to build an AI chat screen. The team asks questions in the tool they already use, and Claude looks up the answers in THG Brain's data.

That works through the Model Context Protocol, which "How to connect Claude to your business data with MCP" explains step by step. For features your paying customers use, the server-route approach in this post is still the right one, because you control the prompt, the permissions and the cost.

The bottom line

Adding AI to a SaaS app is mostly ordinary engineering: one narrow feature, a server route that checks the user, a key that never reaches the browser, rate limits, cost logging and a test set you rerun on every change. At the time of writing a summary on a small model costs a fraction of a cent, so the API bill is rarely the problem; bad output and missing limits are. Start with summaries or classification, measure them, and expand from there. If you want one AI feature added to an app that already works, my Fix Plus Features package is from $200 in about 5 days, and a new SaaS MVP with AI built in starts with the SaaS MVP package from $1,200.

Questions, answered in one line

What is the easiest AI feature to add to a SaaS app?

Summaries are usually the easiest, because the input is data your app already has, the output is short, and a user can check the result at a glance.

Can I call the OpenAI or Anthropic API from the browser?

No, the API key would be visible to anyone who opens developer tools, so calls should go through your own server route that checks the user before calling the model.

How much does an AI feature cost per request?

At the time of writing, summarizing a 3,000-token document into 300 tokens costs about $0.00045 on Claude Haiku 5.5 and about $0.009 on Claude Sonnet 5.5, before any caching discounts.

Do I need a vector database for AI search?

Not always, because Postgres with the pgvector extension handles embeddings for most MVPs, and plain keyword search plus a model to rank results is often enough to start.

How do I stop users from abusing an AI feature?

Limit requests per user and per account, cap input length, set a spend limit with the provider, and log every call so you can spot unusual usage quickly.

Can Thomas Osayi add AI features to my app?

Thomas Osayi's Fix Plus Features package, from $200 in about 5 days, covers up to three fixes plus one small feature such as an AI summary on an existing app.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

SaaS MVP and full-stack web app development

I build SaaS MVPs and full-stack web apps in Next.js, TypeScript and Firebase or Postgres: auth, dashboards, payments, roles and admin tools. Founder of SQWAD.

See the service