Skip to content
SaaSFarersOpen Source · Open Journey
AI13 May 2026 · 9 min read

How to Build an AI SaaS Product: Architecture and Costs

A reference architecture for AI SaaS products, covering gateways, retrieval, evals, per-tenant cost metering, and realistic Indian market build costs.

By SaaSFarers Team
TL;DR

An AI SaaS product needs six layers beyond a normal SaaS stack: a model gateway, a prompt/version registry, a retrieval layer, an eval harness, per-tenant cost metering, and human-in-the-loop review for uncertain outputs. Skipping cost metering is the most common early mistake: teams typically discover their unit economics are broken around month three, right after their first heavy user signs up.

An AI SaaS product needs everything a normal SaaS product needs (auth, billing, multi-tenancy) plus six additional layers: a model gateway, a prompt and version registry, a retrieval layer, an eval harness, per-tenant cost metering, and human-in-the-loop review. Most teams build the product layer well and skip the metering and evaluation layers, which is exactly what breaks first once real, uneven usage arrives around month three.

The Reference Architecture

Think of an AI SaaS product as a normal multi-tenant SaaS application with an AI subsystem bolted on. The subsystem has its own concerns that a standard SaaS tech stack doesn't need to handle.

1. Model Gateway

A single internal service that every AI call goes through, rather than scattering fetch calls to OpenAI, Anthropic, or a local model across your codebase. The gateway handles authentication to model providers, request/response logging, retries, and, critically, routing.

2. Prompt and Version Registry

Prompts change constantly during development and periodically in production. Store them outside application code, versioned, with the ability to roll back a prompt change independently of a code deploy. Teams that hardcode prompts in application logic lose the ability to A/B test or quickly patch a prompt regression without a full release cycle.

3. Retrieval Layer

If your product uses RAG, this is the vector store, embedding pipeline, chunking logic, and reranking step, isolated as its own service so it can be improved, re-indexed, and monitored independently of the rest of the application.

4. Eval Harness

A repeatable set of test cases with expected outcomes, run against every prompt or model change before it ships. Without this, "did that change help or hurt" becomes a matter of opinion and anecdote instead of a number you can check in CI.

5. Per-Tenant Cost Metering

Every model call logged with token counts, tagged by tenant, aggregated into a live cost ledger. This is the layer teams skip most often, and the one that causes the most painful surprises.

6. Human-in-the-Loop Review

A queue where outputs below a confidence threshold, or above a stakes threshold, go to a person before reaching the customer. Not every product needs this on every output, but almost every AI product needs it somewhere.

Layer

Primary purpose

What breaks without it

Model gateway

Central auth, logging, routing

Scattered API keys, no visibility into failures

Prompt registry

Version and roll back prompts

A bad prompt change ships with the next full release

Retrieval layer

Ground answers in current data

Model answers confidently from stale training data

Eval harness

Catch regressions before shipping

"Better" or "worse" becomes a guess, not a measurement

Cost metering

Track spend per tenant

One heavy user silently erases your margin

Human-in-the-loop

Catch high-stakes, low-confidence output

A wrong answer reaches the customer unreviewed

Each layer is small on its own: most are a service and a database table, not a major engineering effort. The cost is in wiring them together consistently across every AI feature you ship, rather than building one feature well and the next one ad hoc.

Unit Economics: Meter Tokens From Day One

Here's the mistake we see most often when reviewing a client's AI SaaS after their first real growth: usage-based costs were never separated by tenant, so nobody notices that one customer is consuming 40% of the model budget while paying for the cheapest plan.

Set up per-tenant token metering before you have real customers, not after. Concretely:

  • Tag every model call with tenant_id at the gateway, not in scattered application code.
  • Log input tokens, output tokens, and model used, per call.
  • Aggregate hourly into a cost-per-tenant view, compared against that tenant's plan and revenue.
  • Alert when any tenant's daily cost crosses a threshold relative to their plan price, before the monthly bill surprises you.

A rough rule that holds across most of the AI SaaS products we've built: your infrastructure and model costs should stay under 25–35% of revenue per tenant at steady state. Without per-tenant visibility, you won't know you've crossed that line until the aggregate provider invoice does it for you.

Model Routing and Fallbacks

Not every query needs your most capable, most expensive model. A classification task, a short summarization, or a routine lookup can often run on a smaller, cheaper model at a fraction of the cost, with a larger model as fallback when confidence is low or the request is flagged as complex.

A simple, effective routing pattern:

  1. Classify the incoming request's complexity (rule-based or with a cheap model call).
  2. Route simple requests to a fast, low-cost model.
  3. Route complex requests, or anything the cheap model flags as low-confidence, to a stronger model.
  4. If the primary provider errors or times out, fall back to a secondary provider automatically rather than surfacing an error to the user.

Teams that skip routing and send every request to their most capable model typically pay 2–4x what they need to for equivalent output quality, especially once volume grows past the first few hundred daily active users.

Latency Budgets

Set a latency budget per feature before you build it, not after users complain. A chat-style interface can tolerate 1–3 seconds with a streaming response. A background workflow step can tolerate 10–30 seconds. An inline autocomplete-style feature needs to stay under 300–500ms or it feels broken, which usually rules out a large model call in that exact path and pushes you toward a smaller model or a cached response.

Retrieval adds 50–300ms on top of generation time; reranking adds more. Budget for the full pipeline, not just the model call, when you're deciding what latency is achievable for a given feature.

Data Privacy: Where Indian and EU Clients Push Back

If you're building for clients rather than only for a consumer product, data residency and processing location come up early and often.

  • EU clients typically ask where data is processed and stored, and whether it leaves the EU at any point in the pipeline, including transiently, inside a model provider's inference call. GDPR-conscious clients often require a data processing agreement naming every subprocessor, model providers included.
  • Indian enterprise and government-adjacent clients increasingly ask the same question in reverse, whether data leaves India, particularly for anything involving personal or financial data, ahead of India's evolving data protection rules.

Design your architecture so the model provider and its region are configurable per deployment, not hardcoded. It's considerably cheaper to build that flexibility in from the start than to retrofit it after a client contract depends on it.

What Breaks in Month Three

Month one and two run smoothly because usage is light and forgiving. By month three, three things typically surface at once:

  • A heavy user's actual cost reveals a pricing plan that doesn't cover its own model spend.
  • An edge case your eval set never covered starts reaching real customers and produces a confidently wrong answer.
  • Latency, fine under test load, degrades under real concurrent traffic because the retrieval layer or a rate-limited model API becomes the bottleneck.

None of these are surprising in hindsight. They're the direct, predictable cost of skipping metering, evals, and load testing during the build phase because the deadline was the demo, not the third month of production.

Build It Once, Build It Right

If you're scoping an AI SaaS product and want the architecture reviewed before you commit months of engineering to it, our AI products team has built and hardened this exact stack across multiple client engagements, and our broader SaaS product development practice handles everything around it: auth, billing, multi-tenancy. If you'd rather learn to build this yourself, SaaSFarers Academy's AI Engineering course walks through this reference architecture on live projects, not slides.

ai saas productarchitecturellmmulti-tenantunit economics
Questions

Frequently asked

A first production version with one core AI feature, multi-tenant auth, and basic metering typically runs ₹15–35 lakh ($18,000–$42,000) in engineering effort over three to five months, excluding ongoing model API costs. Complexity in retrieval, evaluation, and compliance can push this higher; a narrow single-feature MVP can come in lower.

Keep reading

More on ai

AIAI

AI Agents in Production: What Actually Works

An honest look at AI agents in production: where they work, where they fail, the guardrails that matter, and a checklist before you ship one.

20 May 20268 min read
AIAI

RAG vs Fine-Tuning: Which One Does Your AI Product Need?

RAG vs fine tuning compared on cost, latency, freshness, and failure modes, with a clear rule for choosing the right one for your AI product.

06 May 20268 min read

Tell us what you are trying to build.

Whether it is a product, a system, or a career, the first conversation is with an engineer.