Edge Functions
The four server-side functions, what each one does, and the shape they share.
NativeExpress includes four Supabase Edge Functions . They live in supabase/functions/ and run on Deno.
| Function | What it does | Needs secrets |
|---|---|---|
chat | Streams AI chat responses, persists threads and messages | Yes |
generate | Single-shot image generation for the Create tab | Yes |
identify | Object identification for the Scan tab | Yes |
delete-account | Deletes the signed-in user’s account | No |
Shared helpers live in supabase/functions/_utils/:
auth.tsauthenticates the caller from theAuthorization: Bearer <access_token>header and returns the Supabase user.ai.tsbuilds the OpenRouter provider, checks RevenueCat entitlements, enforces the monthly free quota, and handleschat-mediauploads and downloads.
The three AI functions will not work until you set the server-side secrets, which is the most common reason chat “does nothing” on a fresh install. Start with Secrets.
How an AI request flows
- The app sends the user’s Supabase access token in the
Authorizationheader. - The function authenticates the user (
authenticateUser) and rejects requests without a valid token. - It checks the gates that apply: model capability, Pro entitlement, monthly quota.
- It calls OpenRouter through the Vercel AI SDK.
- It persists the result to Postgres and, for images, to the private
chat-mediastorage bucket.
The provider key is kept only in function secrets, so it never reaches your app bundle.
Last updated on