Add AI features with OpenAI
Call an LLM from your app (summaries, chat, generation). The API key is secret and used only from a server function, so it never ships to the browser.
1. Before you start
Create an OpenAI account and add billing — API usage is pay-as-you-go and separate from any ChatGPT subscription.
The call runs in a server function (to keep the key secret), which requires a paid plan.
2. Where to find your key
- Open the API keys page and create a secret key.
- Copy it now — it is shown once.
- Paste it in the key panel under a secret name (no VITE_), e.g. OPENAI_API_KEY.
The key is read only by your server function via the environment — it must never appear in client code or the chat.
3. Control cost
Set a monthly usage limit in your OpenAI account so a bug or a spike cannot run up the bill. Pick a smaller model for simple tasks.
4. Common problems
401 invalid_api_key: the key is wrong, revoked, or from another org.
429 / quota exceeded: you hit your usage limit or have no billing set up.
The key leaked to the browser: it was declared with a VITE_ name — a secret must NOT use VITE_. Rotate the key and re-declare it correctly.