How to add secure, GDPR-compliant AI to your Lovable app
By Göran Sandahl -
You built an app in Lovable, and now you want it to do something smart: summarize, chat, classify, draft. The usual path is to grab an OpenAI or OpenRouter key and ask Lovable to wire it up. (Lovable also ships a built-in AI connector, which is fine for a quick demo, but it picks the model for you and gives you no policy controls.)
That gets you a working feature, but it also means you've shipped ungoverned AI. There's no ceiling on what the app can spend if a user (or a bug) hammers the endpoint. You can't see what's being sent to the model or what it costs per call. There's nothing filtering personal data out of prompts. And if your users are in Europe, you don't have a good answer for where their data actually goes. Lovable can host your app's data in the EU, but every AI call still leaves for wherever your model provider runs.
This post is about the alternative: routing your Lovable app's AI calls through the Opper gateway. The result is that you now control the AI inference in your app: which models it uses, what it can spend, what leaves in a prompt, and where in the world it runs. Every token your app consumes and produces flows through infrastructure you can see and steer. We call that trusted tokens. The setup takes a few minutes, and most of the work is done by Lovable itself. You paste one prompt.
Here's the architecture we end up with:
Why route your Lovable app through an AI gateway
Putting a gateway between your app and the model buys you three things a raw provider key can't:
- Governance. Set a spend cap so a runaway feature can't surprise you on the bill, add guardrails that filter PII or unwanted content before it reaches the model, and pin exactly which models your app is allowed to call.
- GDPR and EU data residency, for the AI calls and not just the database. Lovable can keep your app's data in the EU, but AI inference is a separate data flow with its own destination. Opper is EU-hosted, offers a DPA and a published sub-processor list (we're happy to sign a DPA, just reach out), and lets you pin traffic to EU-deployed models, so "where do my users' prompts go?" has a real answer too.
- One key, every model. One credential gives your app access to every major provider's models. When a better or cheaper model ships, you swap a model id. No re-integration, no new keys.
And the supporting point that matters for any vibe-coded app: the only credential involved is a single Opper key, stored server-side in your app's backend. Nothing sensitive ships to the browser, and there's no pile of per-provider keys to rotate.
If you're already running other AI workloads through the Opper gateway, there's nothing new to configure: your Lovable app's inference simply joins the same setup: the same models, spend caps, guardrails, and dashboard you already use, with the app showing up alongside the rest of your traffic. Optionally, make the Lovable app its own project and issue it a dedicated API key, which gives it separate spend caps, policies, and metering from your other workloads.
Set up in three steps
1. Get an Opper API key
Sign up at Opper (it's pay-as-you-go with no markup on inference) and create an API key from the dashboard. That key can call any model in the gateway. Browse the full list at opper.ai/models to pick one, or simply ask Lovable and it will find the supported models for you. aws/claude-sonnet-4-6-eu is a good default if you want capable-and-EU-hosted.
2. Tell Lovable to integrate Opper
There's no backend setup to do first. Every Lovable project comes with a built-in cloud backend that includes server-side functions and a secret store, which is all this integration needs. Lovable handles that part.
So this step is the whole trick. Opper publishes machine-readable integration instructions at skills.opper.ai, written for exactly this situation: an AI coding agent that needs to wire up the gateway correctly. Paste this into Lovable's chat:
Add an AI chat feature to this app using the Opper gateway.
Use curl to download, read and follow: https://skills.opper.ai
Use the model id "aws/claude-sonnet-4-6-eu", and ask me for the
OPPER_API_KEY secret if it is not set yet.
Adjust the first line to whatever feature you actually want: a support chat, a summarizer, an autocomplete. The skill takes care of the rest, including keeping the AI calls server-side and out of your app's frontend code.
3. Paste the key when Lovable asks
As Lovable builds the integration, it detects that the backend function needs the OPPER_API_KEY secret and asks for it right in the chat. Paste the key from step 1, and it lands in your backend's secret store, never in your app's code and never in the browser.
For reference, this is all the configuration involved:
| Field | Value |
|---|---|
| Base URL | https://api.opper.ai/v3/compat |
| Auth | Bearer with your Opper API key |
| Key location | OPPER_API_KEY secret in your app's cloud backend |
| Example model | aws/claude-sonnet-4-6-eu |
Because the endpoint is OpenAI-compatible, Lovable can use the OpenAI SDK it already knows. Only the base URL, key, and model id change.
Verify it works
Use the AI feature in your app's preview: send a chat message, trigger a summary. Then open the Opper dashboard: the call shows up metered with model, cost, latency, and token counts. That's your confirmation the traffic is flowing through the gateway rather than straight to a provider.
If a call doesn't appear, the usual suspect is a leftover code path that still calls a provider directly. Ask Lovable to "show me every place the app calls an AI API" and have it route stragglers through the Opper function.
Turn on the governance
Metering alone is already more than a raw provider key gives you, but the point of trusted tokens is what you switch on next, all from the dashboard:
- Spend caps. Set a per-project ceiling so your app has a worst-case bill, not an open tab.
- Guardrails. Filter PII and unwanted content out of prompts and responses before they reach the model.
- Model and region pinning. Restrict the project to the models you've vetted, and keep EU traffic on EU-deployed models.
- Tracing. Every call is metered out of the box; full traces with prompts, responses, and evaluation scoring come with the Control Plane plan when you want to debug or improve quality.
None of this requires touching your Lovable app again. It's policy applied at the gateway, which is rather the point: the AI inference in your app is now something you control, not something that just happens to work.
Lovable AI security and GDPR FAQ
Are API keys safe in a Lovable app?+
Only if they stay server-side. Any key that ends up in your app's frontend code is readable by anyone who opens the browser's dev tools. The safe pattern is the one in this post: keep a single key in your backend's secret store and route every AI call through a server-side function, never from browser code.
Is a Lovable app GDPR-compliant?+
Lovable offers EU data residency and a DPA for your app's data, but GDPR compliance is a property of every data flow in your app, including AI calls, which travel to wherever your model provider runs. Routing inference through an EU-hosted gateway with EU-deployed models, a DPA, and a published sub-processor list closes that gap for the AI part of your stack. Opper is happy to sign a DPA; contact hello@opper.ai.
Do I need Supabase to add AI to a Lovable app?+
No. Every Lovable project ships with a built-in cloud backend that includes server-side functions and a secret store, which is all this integration uses. Lovable handles the backend; you just paste the prompt and the key.
Can I switch AI models without rebuilding my Lovable app?+
Yes. That's one of the main reasons to use a gateway. Your app talks to one endpoint with one key, so switching from one provider's model to another is a one-line model-id change (or a dashboard setting), not a re-integration.
Get started
If you're shipping AI features from Lovable, this is the cheapest way to take control of the AI inference in your app: sign up, add one secret, paste one prompt. The docs cover everything the skill sets up. Questions? Find us on Discord or drop us a line at hello@opper.ai.