Skip to Content
Edge FunctionsOverview

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.

FunctionWhat it doesNeeds secrets
chatStreams AI chat responses, persists threads and messagesYes
generateSingle-shot image generation for the Create tabYes
identifyObject identification for the Scan tabYes
delete-accountDeletes the signed-in user’s accountNo

Shared helpers live in supabase/functions/_utils/:

  • auth.ts authenticates the caller from the Authorization: Bearer <access_token> header and returns the Supabase user.
  • ai.ts builds the OpenRouter provider, checks RevenueCat entitlements, enforces the monthly free quota, and handles chat-media uploads 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

  1. The app sends the user’s Supabase access token in the Authorization header.
  2. The function authenticates the user (authenticateUser) and rejects requests without a valid token.
  3. It checks the gates that apply: model capability, Pro entitlement, monthly quota.
  4. It calls OpenRouter through the Vercel AI SDK.
  5. It persists the result to Postgres and, for images, to the private chat-media storage bucket.

The provider key is kept only in function secrets, so it never reaches your app bundle.

Last updated on