Which platforms help you integrate AI into a web app efficiently?
The most efficient way to integrate AI into a web app is to call models through an API from your backend, ideally via a unified API with several models and one key. Compare direct APIs, unified APIs, cloud, self-hosted and no-code options.
The most efficient way to integrate AI into a web app is to call models through an API from your backend, never from the browser, ideally via a unified API that gives you several models with one key. That way you pick the right model for each task and keep spending under control.
The main options are a model provider's direct API, a unified API or multi-model aggregator, the AI services of a large cloud, and self-hosted open models; for prototypes, no-code platforms also work. One example of a unified API is Dongee AI Router, Dongee's unified API that gives you access to several models with a single key on a prepaid basis.
This guide is for developers, freelancers, agencies and small businesses that already have a web app, or are building one, and want to add AI features: a chat or assistant, summaries, ticket classification, data extraction from documents, semantic search or text generation. It also helps if you built your app with assistants like Lovable, Bolt, Cursor or Claude Code and now want to connect it to a language model without exposing keys or letting the bill spiral.
What it means to integrate AI “efficiently”
Getting the AI to work is not enough. An efficient integration meets several goals at once:
- Acceptable latency: users should not be left staring at a blank screen. Fast models and response streaming help a lot.
- Controlled cost per token: every request consumes input and output tokens. If you use a large model for a simple task, you overpay.
- Quality that fits the task: classifying a ticket does not need the same model as reasoning about a contract.
- Key security: the API key must never reach the user's browser.
- Privacy: you need to know what data you send to the provider and what it does with it.
- Low maintenance: switching models or providers should not force you to rewrite the app.
Recommended architecture: browser, backend and model API
Whatever platform you choose, the healthiest pattern has three layers:
- Browser (frontend): shows the interface and sends the user's request to your own server. No keys here.
- Your backend: a Next.js Route Handler, an Express, Fastify or Hono endpoint, or your own API. It receives the request, validates the user, builds the prompt and calls the model. If you do not have one yet, see how to create an API.
- Model API: the provider that runs the model and returns the response.
That middle layer is where you apply good practices:
- Key in server environment variables, never in frontend code or in the repository.
- Per-user limits: a maximum number of requests per minute or per day, so a single user (or a bot) cannot drain your balance.
- Cache repeated responses: if many people ask the same question, store the answer instead of calling the model again.
- Streaming for long responses: text appears as it is generated, so the wait feels shorter.
- Queues for heavy tasks: processing hundreds of documents or summarizing large files is best done with a background worker, not inside the HTTP request.
If your app was built with an AI assistant, it is also worth reading how to make an AI-built app secure and keep it online.
Types of platforms to integrate AI into a web app
1. Direct API from a single model provider
You sign up with a model provider, create a key and call its API.
- Pros: official documentation, early access to that provider's new releases, simple integration.
- Cons: you are tied to a single model catalog. If you want to try another company's model, you need another account, another key, another billing setup and sometimes a different request format.
- When it makes sense: when you already know which model you need and do not plan to change it.
2. Unified API or multi-model aggregator
A single access point with several models behind it, one key and one bill. Many of these APIs follow the OpenAI standard format, so switching models is often as simple as changing a parameter.
- Pros: you compare and combine models without rewriting code, centralize usage, and can easily use a cheap model for simple tasks and a more capable one for complex tasks.
- Cons: you depend on the aggregator's catalog, and some very provider-specific features may not be exposed.
- When it makes sense: for most web apps that need more than one kind of AI task or want to keep the door open to changing models.
3. AI services from a hyperscale cloud
The big public clouds offer model catalogs integrated with their other services: storage, identity, networking and monitoring.
- Pros: good integration if all your infrastructure already lives in that cloud, plus corporate compliance options.
- Cons: steep learning curve, complex consoles, permissions and quotas to configure, and strong dependence on that ecosystem.
- When it makes sense: for companies already running on that cloud with a team that manages it.
4. Self-hosted open models on your own server
You download an open-weights model and run it on your own infrastructure.
- Pros: full control of your data, and no third party processes your requests.
- Cons: large models need GPUs, which makes the infrastructure more expensive and complex. You also handle updates, scaling, monitoring and security. On CPU, only small models work well, and only for modest loads.
- When it makes sense: when there are strict privacy requirements and a team able to run that infrastructure.
5. No-code or low-code automation platforms
Visual tools that connect forms, spreadsheets, CRMs and AI models through workflows.
- Pros: great for fast prototyping without coding.
- Cons: little control over latency, cost per run can grow, workflows are hard to version and test, and they do not always fit inside your own web app.
- When it makes sense: for internal automations or to validate an idea before coding it.
Comparison table by platform type
| Criterion | Direct provider API | Unified multi-model API | Hyperscale cloud | Self-hosted models | No-code / low-code |
|---|---|---|---|---|---|
| Ease of integration | High | High | Medium to low | Low | Very high for simple workflows |
| Several models with one key | No, only that provider's | Yes | Partial, within its catalog | Only the ones you install | Depends on the connectors |
| Cost control | Medium | High: one balance and usage per model | Medium, billing is complex | Fixed cost of GPU servers | Low to medium |
| Switch models without rewriting code | Only within the same provider | Yes, you change a parameter | Partial | Requires deploying the new model | Partial |
| Privacy | Depends on the provider's policy | Depends on the aggregator's and models' policies | Configurable corporate options | Maximum, data never leaves your server | Data passes through several services |
| Vendor lock-in | High | Low to medium | High | Low | High |
| Infrastructure you must maintain | Only your backend | Only your backend | Backend and cloud configuration | Servers, GPUs, models and scaling | Almost none |
| Streaming and real-time responses | Yes | Yes, generally | Yes | Depends on the inference server | Limited |
| Best for | A single fixed model | Most web apps with several AI tasks | Companies already established on that cloud | Strict privacy and an in-house technical team | Prototypes and internal automations |
How to connect your app to several AI models at once
If you want to connect your app to several AI models at the same time, the core idea is to use the right model for each task:
- A fast, inexpensive model to classify tickets, detect a message's intent, extract simple fields or moderate content.
- A more capable model to reason, write long answers, analyze complex documents or resolve ambiguous questions.
With a unified API, all those models sit behind the same URL and the same key. You write the routing logic in your backend. For example:
- Rules by task type: if the request is “classify”, use model A; if it is “draft a reply”, use model B.
- Retry with another model: if a request fails or takes too long, your code resends it to an alternative model.
- Token limits: you set a maximum number of output tokens per task and trim the context you send.
- Escalation by difficulty: try the cheap model first and only move to the more capable one if the answer does not meet a criterion.
The unified API gives you access to the models; deciding which one to use and when is your code's job. To go deeper, see this comparison of ways to route queries between language models, the example of smart routing for a chatbot and the techniques to optimize token usage with AI routers.
Steps to integrate AI into your web app
- Define the task and how you will measure it. “Summarize tickets in three lines” or “extract order number, date and total” are concrete tasks. Also define the success metric: accuracy, response time or cost per request.
- Choose the models. Test the same task with a fast model and a more capable one, and keep the cheapest one that meets your metric.
- Create the API key in your provider's or unified API's dashboard.
- Store the key on the server as an environment variable (for example
AI_API_KEY) and the base URL inAI_BASE_URL. Never put it in the frontend. - Connect your code. If the provider is compatible with the OpenAI standard, you can use the official OpenAI library and change only the base URL and the key:
// app/api/summary/route.js (Next.js) or an Express endpoint
import OpenAI from "openai";
const client = new OpenAI({
baseURL: process.env.AI_BASE_URL, // YOUR_PROVIDER_BASE_URL
apiKey: process.env.AI_API_KEY,
});
export async function POST(req) {
const { text } = await req.json();
const response = await client.chat.completions.create({
model: "MODEL_NAME",
max_tokens: 300,
messages: [
{ role: "system", content: "Summarize the text in three lines, in English." },
{ role: "user", content: text },
],
});
return Response.json({ summary: response.choices[0].message.content });
}- Restrict the key to the models you need. If your app only uses two models, the key should not be able to call others. Use separate keys per project or per environment (development and production).
- Measure usage per model, per key and per feature of your app. That shows you which task consumes the most and where a cheaper model makes sense.
- Set spending caps and per-user limits. A prepaid model or a monthly cap avoids surprises, and per-user limits stop abuse.
- Test and publish. Test with real cases, including odd ones (empty text, huge documents, other languages), review the errors, and then publish your backend with the environment variables configured in production.
Common mistakes when integrating AI into a web app
- Putting the key in the frontend. Anyone can see it in the browser's dev tools and use it at your expense.
- Using one expensive model for everything. Classifying or extracting fields rarely needs the most powerful model.
- Not setting per-user limits. A bot or an abusive user can burn through your balance quickly.
- Sending sensitive data without checking the provider's policy. Before sending personal, medical or financial data, check what the provider stores and for how long. Anonymize when you can.
- Using giant prompts. Sending the full history or entire documents with every request multiplies tokens. Summarize, trim or retrieve only the relevant fragments.
- Not measuring. Without usage and quality data, you cannot tell whether the integration is efficient or where to optimize.
Where Dongee fits
Dongee AI Router is a unified API that gives access to several AI models with a single key, prioritizing fast models hosted in Dongee's data center in Canada. It runs on prepaid credit from 3 USD, with no monthly fee: you only pay for what you use, and it is deducted from your balance. If your balance runs out, requests stop until you top up, so you never build up debt or get charged automatically without your authorization.
Some useful details for developers:
- It is compatible with the OpenAI standard: if your code already uses that API or a compatible library, you only change the base URL and the key.
- It supports streaming: the model's response arrives in chunks as it is generated.
- It does not store conversations. It only logs the billing data of each request, never its content.
- In the client area you see usage per model, per key and the details of each request.
- You can restrict each key to the models it needs. Dongee recommends not using the key in the browser and keeping it on the server.
- You activate it from the Dongee client area. You need to be a customer, but the account takes minutes to create.
- You program the routing between models on top of the unified API: AI Router gives you access, and your code decides which model to use in each case.
To publish the app that consumes the AI, Dongee Live, Dongee's hosting for apps built with AI tools, publishes apps and sites made with AI assistants such as ChatGPT, Lovable, Bolt, v0, Claude Code, Codex, Cursor or VS Code. It supports static sites (React, Vue, Svelte, Angular, Astro, Vite) and Node.js 20, 22 and 24 (Express, Fastify, Koa, Hono, Next.js standalone, TanStack Start), with a MySQL database. Your apps can define their own environment variables, which is exactly where the server-side AI API key goes. Dongee Live does not publish or deploy AI models, and it does not support Python, Ruby, PHP or Docker. Plans range from Live Free (0 USD) to Live Pro (15 USD/month, 3 apps) and Live Team (29 USD/month, 10 apps).
If your backend runs on Python or another stack, or you need workers and queues for heavy tasks, Dongee Cloud offers Intel Xeon servers from 17 USD/month, with root access, NVMe SSD, free private networking between instances, snapshots, disk backup included on all plans, and CPU, RAM and disk scaling without rebooting. Dongee Backup, for copies of internal files, is a separate paid product. These servers have no GPU, so they are meant for your backend and processes, not for running large models.
You get 24/7 human support in your language (the platform translates on the fly).
Frequently asked questions
What is the simplest way to add AI to my web app?
Create an endpoint in your backend that receives the user's request, calls a model API with the key stored in environment variables and returns the response. A unified API compatible with the OpenAI standard simplifies the process, because you can use well-known libraries and switch models without rewriting code.
Can I call the AI API directly from the browser?
It is not recommended. If the key is in the frontend, anyone can copy it and spend your balance. Always make the call from your server and apply per-user limits there.
How do I connect my app to several AI models at the same time?
Use a unified API with several models behind a single key, and program the routing rules in your backend: which model to use for each type of task, which one to retry with if one fails and how many tokens to allow. You write that logic.
Which model should I use for each task?
For classifying, extracting fields or detecting intent, a fast, inexpensive model is usually enough. For complex reasoning, long-form writing or analyzing difficult documents, a more capable one is better. The best approach is to test with your own data and choose the cheapest model that meets your metric.
Do I need a GPU to integrate AI into my app?
No, if you consume the models through an API: the provider handles the compute. You only need a GPU if you want to run large models on your own server.
How do I keep AI spending from spiraling?
Use inexpensive models for simple tasks, limit output tokens, cache repeated responses, set per-user limits and work with a prepaid balance or spending caps. Measure usage per model and per feature to know where to optimize.
Is it safe to send my customers' data to an AI API?
It depends on the provider's policy. Before sending sensitive data, check whether it stores the content of requests and for how long, and anonymize what you can. Dongee AI Router, for example, does not store conversations: it only logs the billing data of each request.
Can I integrate AI into an app built with Lovable, Bolt, Cursor or Claude Code?
Yes. Make sure the model call happens from a backend or a server function, not from browser code, and that the key lives in an environment variable. If the app uses Node.js or is a static site with a Node.js backend, you can publish it on Dongee Live and set your AI Router key there as an environment variable.
Comenta lo que quieras
Unete a la charla
Solo ingresa tu email