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

How do I connect OpenAI?

Last checked 31 Aug 2026

Short answer

For most cases, use Lovable AI (the built-in AI Gateway) so users don't need their own key; if you specifically need OpenAI, ask Lovable to store your API key as a secret and call it from a server function.

Check whether you need OpenAI specifically

Lovable AI (its built-in AI Gateway) lets your app call AI models without visitors supplying their own API key, and without you managing a separate OpenAI account. For most "add AI to my app" requests — chat features, text generation, summarisation — this is the simpler starting point:

"Add an AI chat feature to the [page] page using Lovable AI."

If you specifically need OpenAI's API

Some projects need a specific OpenAI model, fine-tune, or feature Lovable AI doesn't expose. In that case:

  1. Get an API key from your OpenAI account.
  2. Ask Lovable to store it as a server-side secret.
  3. Ask Lovable to create a server function that sends the request to OpenAI's API and returns the result.
  4. Call that server function from your UI — never call OpenAI directly from front-end code.

"Create a server function that sends the user's message to OpenAI's chat completions endpoint using my API key, and return the response to the chat UI."

Cost and rate limits

OpenAI billing is separate from your Lovable credits — usage against your OpenAI key is charged by OpenAI directly. Watch for rate limits on your account tier; a spike in traffic can throttle the app if you're not monitoring usage.

What usually goes wrong

  • Exposing the OpenAI key in client code, which lets anyone extract it and run up your bill.
  • No usage limits per user, so a single visitor can rack up large costs by spamming a chat feature — ask Lovable to add basic rate limiting.
  • Long-running or streaming responses timing out on the server function — clarify whether you need streaming support up front.

For production AI features with real usage, budget monitoring and abuse protection matter — if that's more than a quick add-on, PromptSites.com can build it properly.

Sources

Was this answer helpful?

Related questions

Website made, maintained and hosted by PromptSites.com

PromptSites logo