Why is my API working in preview but not production?
Last checked 31 Aug 2026
Short answer
This is usually a missing secret, environment mismatch, or a domain restriction that only applies once the app is published — check that every secret and allowed-domain setting has been applied to production, not just preview.
Most likely causes, in order of frequency
- Secret not set for the published app. Some setups keep preview and production configuration separate — confirm the API key/secret was saved and is actually available to the deployed server function, not just during your Chat session.
- Domain/referrer restrictions. Keys restricted to specific domains (common with Google Maps, and CORS allow-lists on APIs you call) often only include your preview URL or
localhost, not your published custom domain. Add the production domain to the allow-list. - Different environment variables. If the third-party service has separate test/live keys (Stripe is the classic example), check you're using live keys in production and test keys only in preview.
- CORS configuration on the third-party API restricting which origins can call it — preview and production are different origins.
- Webhook URLs pointing at the wrong environment, so events land nowhere once you've published.
How to check systematically
- Ask Lovable to confirm which secrets exist and whether they're populated.
- Open your browser's developer console/network tab on the production URL and look at the actual error returned by the third-party API — "unauthorized", "forbidden", "origin not allowed" all point to different causes above.
- Compare the production custom domain against every allow-list (API key restrictions, CORS settings, OAuth redirect URLs) you configured during setup.
- Check the provider's own dashboard/logs (Stripe, Google Cloud, etc.) for the actual rejected request — most log the reason.
What usually goes wrong
- Restricting an API key to
localhostor the Lovable preview domain during testing and forgetting to add the real production domain before publishing. - Test-mode keys left in place after going live, which some providers block for real traffic.
- Publishing to a new custom domain without updating OAuth redirect URIs or webhook URLs registered with the third party.
If you've checked the obvious causes and it's still failing, PromptSites.com can trace it through the logs and fix the underlying config.
Sources
Was this answer helpful?
Related questions
- AnswerHow do I install Google Tag Manager?Ask Lovable to add your GTM container snippet to the site's shared head and body, then manage individual tags (analytics, ads, pixels) from within Tag Manager itself.
- AnswerHow do I connect an API to Lovable?Describe the API and what you want it to do in Chat; Lovable will typically wire the call through a server function (Edge Function) so any API key stays off the client.
- AnswerHow do I connect Meta Pixel?Ask Lovable to add your Meta Pixel ID as a script in the site's shared head, and fire a PageView (or custom) event on each route change since Lovable apps are single-page apps.
- AnswerHow do I use webhooks?Webhooks let external services notify your Lovable app when something happens; ask Lovable to create a server function URL as the webhook endpoint, and configure that URL in the third-party service.