Building an LLM feature into a SaaS product is quickly done technically: an API call, a prompt, a response. The difficulties appear in production — with many tenants, changing models, fluctuating costs and customers who want to know where their data goes. This article describes the architecture patterns we use in our own products.
A gateway layer instead of scattered calls
The most common architectural mistake is model calls scattered across the code. Better is a dedicated layer that every call goes through: it knows model and provider, sets timeouts and retries, logs consumption, checks quotas and encapsulates provider-specific details. That lets you switch a model without rebuilding the application, and every feature benefits from the same safeguards. Calls run exclusively server-side; API keys never belong in the browser.
Enforcing tenant context
In a multi-tenant product a model must never see another tenant’s data. For RAG features this means: search filters by tenant and permission before content reaches the prompt, ideally secured by row-level security at database level. For tools via tool calling, the server checks every call against the current user’s rights. Tenant boundaries belong in code, not in the prompt, because a prompt can be talked round through prompt injection.
Structured outputs
Where the application works further with the result, request structured outputs against a schema and validate them rather than parsing free text. If validation fails, a controlled fallback follows: a bounded retry or a clear message. That turns a probabilistic answer into a reliable interface.
Evaluation as part of the pipeline
Every change to prompt, model or retrieval can improve or worsen quality, often in unexpected places. A fixed evaluation set with realistic and hard cases therefore runs with every change, like a test run. How to evaluate features without a single correct answer is covered in our article on evaluating LLM features.
Controlling cost per tenant
Tokens are variable costs. Without measurement per feature and tenant, nobody knows which usage drives the bill. The gateway layer records consumption, sets quotas per plan and allows a kill switch for the cost case. Caching recurring prompt parts and using smaller models for simple tasks lower costs further. Planning is covered in our article on AI cost management.
Long tasks in the background
Summarising large documents, extracting from many files or multi-step agent flows take longer than a request-response cycle can bear. Such tasks run in background jobs with status, resumption after errors and notification on completion. For interactive features, streaming markedly improves perceived speed.
Observability with privacy
In production you need insight: latency, errors, cost, user ratings and samples of outputs. At the same time prompts often contain personal data. The answer is a deliberate selection of what is logged, with masking and limited retention. More in our article on observability for AI features.
Provider, region and contracts
Where prompts go is a question of trust for customers in the DACH region. Providers processing in the EU, contractually excluded training on customer data and a data processing agreement are the foundation; for data from Switzerland the question of disclosure abroad comes on top. A comparison of the major providers from this angle is in our article Claude API vs OpenAI for EU SaaS.
Before going live
The steps from prototype to production feature are summarised in our checklist on production readiness of LLM features. For classification under the AI Act, such as the transparency obligations for chatbots, see our AI Act 2026 guide. We support the path from demo to product through our prototype to production offer.

