Skip to content
Every tutorial here is 100% free — and always will be
LSLovableStudent

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

  1. 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.
  2. 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.
  3. 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.
  4. CORS configuration on the third-party API restricting which origins can call it — preview and production are different origins.
  5. Webhook URLs pointing at the wrong environment, so events land nowhere once you've published.

How to check systematically

  1. Ask Lovable to confirm which secrets exist and whether they're populated.
  2. 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.
  3. Compare the production custom domain against every allow-list (API key restrictions, CORS settings, OAuth redirect URLs) you configured during setup.
  4. 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 localhost or 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

Website made, maintained and hosted by PromptSites.com

PromptSites logo