NewHuxly MCP — Connect Claude, Cursor & Codex.Learn more
HuxlyDocsEdge Functions

Edge Functions

Add server-side logic to your app. If your app needs a secret API key, a webhook handler, or server-side validation — you need an edge function.

What is an edge function?

A small piece of code that runs on a server, not in your app. Your app calls it like an API. The function does the sensitive work (calls OpenAI, charges a card, queries a database with admin permissions), then returns a clean result to your app.

You need one whenever:

You don't need one for:

Pick your backend

Huxly supports three providers. Different tradeoffs.

🖼️
Screenshot placeholder
Huxly's Connect Backend picker with Supabase marked Recommended and Firebase marked Advanced
Replace this <Screenshot/> with a real <img/>
SupabaseRecommended
Setup time: 2 minutes
Most users. Single anon key, no IAM, Deno-based functions.
FirebaseAdvanced
Setup time: 15–30 minutes (one-time)
Users with existing Firebase projects, Firestore data, or Firebase Auth already wired.
Cloudflare Workers
Setup time: Coming soon
Edge-fast inference, free tier covers most apps.
Recommended
If you're starting fresh and not sure → pick Supabase. You can always migrate later.

Setup: Supabase (recommended)

The easy path. Two clicks and you're done.

Step 1 — Connect Supabase

In Huxly's chat page, open the Database tab in the left sidebar. Pick Supabase. Paste two values from your Supabase project:

Both are on your Supabase dashboard → Project Settings → API.

🖼️
Screenshot placeholder
Huxly's Supabase connection form with the two fields highlighted
Replace this <Screenshot/> with a real <img/>

Step 2 — Ask the AI for an edge function

Just describe what you want:

Note
"Add an OpenAI food scanner that takes an image and returns nutrition data"

The AI generates:

Step 3 — Add your API key as a secret

In Huxly's Edge Functions panel, click the Secrets tab. Add OPENAI_API_KEY (or whichever key the function needs) with your real value.

Step 4 — Click Deploy

Huxly pushes the function + secret to Supabase. Takes ~10 seconds. You're done.

Setup: Firebase (advanced)

Firebase Cloud Functions require a one-time IAM setup per project. Once done, future functions work without further configuration.

Heads-up
Why is this longer than Supabase? Firebase runs on Google Cloud Platform, which has a stricter security model. Each permission has to be explicitly granted to the deployer service account and the runtime service account. Huxly automates what it can; the rest is 5 clicks in Google Cloud Console.

Step 1 — Make sure your Firebase project is on the Blaze plan

Cloud Functions require pay-as-you-go billing. The free tier is generous — most small apps stay free.

Open: Firebase Billing page for your project. If it says "Upgrade to Blaze" — click that. Add a billing account.

Step 2 — Connect Firebase to Huxly

Open Huxly's Database tab → pick Firebase. You'll need a service account JSON key from Google Cloud Console.

Note
Where to get it: Firebase Console → Project Settings → Service Accounts → "Generate new private key" → downloads a .json file.

Paste the contents into Huxly's form. Done.

🖼️
Screenshot placeholder
Huxly's Firebase connection form with the JSON paste field
Replace this <Screenshot/> with a real <img/>

Step 3 — Enable Secret Manager API

Open the Secret Manager API page for your project. Click Enable. Wait 30 seconds for propagation.

🖼️
Screenshot placeholder
Google Cloud Console showing Secret Manager API page with Enable button highlighted
Replace this <Screenshot/> with a real <img/>

Step 4 — Grant deploy permission

The deployer service account (firebase-adminsdk) needs permission to "act as" the runtime service account.

  1. Open Service Accounts in Cloud Console
  2. Click the row for <project-id>@appspot.gserviceaccount.com (App Engine default — this is the runtime)
  3. PERMISSIONS tab → GRANT ACCESS
  4. New principals: paste firebase-adminsdk-fbsvc@<project-id>.iam.gserviceaccount.com
  5. Role: Service Account User
  6. Save
🖼️
Screenshot placeholder
Grant Access dialog with the principal and role filled in
Replace this <Screenshot/> with a real <img/>

Step 5 — Grant secret-read permission

The runtime needs permission to read secrets at startup.

  1. Open IAM page in Cloud Console
  2. Find the row for <project-id>@appspot.gserviceaccount.com
  3. Click the pencil icon (edit roles)
  4. ADD ANOTHER ROLE → search for Secret Manager Secret Accessor
  5. Save

Step 6 — Wait 5 minutes

Google IAM caches take 5–15 minutes to fully propagate. Skipping this wait causes "operation in progress" loops.

Step 7 — Ask the AI for an edge function and create your secrets

Same as Supabase Step 2 — describe what you want and the AI generates both the function and the app-side caller.

For each secret the function declares:

  1. Open Secret Manager
  2. + CREATE SECRET
  3. Name: exactly matching what the function uses (e.g. OPENAI_API_KEY)
  4. Value: your actual key
  5. Save
🖼️
Screenshot placeholder
Secret Manager with + CREATE SECRET highlighted
Replace this <Screenshot/> with a real <img/>

Step 8 — Click Deploy in Huxly

Huxly handles the rest automatically:

If anything is missing, you'll see a setup-required modal with the exact GCloud link to fix it.

🖼️
Screenshot placeholder
Huxly's deploy success state with green Deployed badge and function URL
Replace this <Screenshot/> with a real <img/>

Calling the function from your app

The AI generates the calling code for you, but here's what it should look like:

Supabase (Deno function)

import { supabase } from '@/lib/supabaseClient';

const { data, error } = await supabase.functions.invoke('analyzeFood', {
  body: { imageBase64, mimeType },
});

Firebase (Callable function)

import { getFunctions, httpsCallable } from 'firebase/functions';
import app from '@/lib/firebaseConfig';

const fn = httpsCallable(getFunctions(app), 'analyzeFood');
const { data } = await fn({ imageBase64, mimeType });
Note
For Firebase callable functions, your app must also do anonymous sign-in on launch so the function's auth check passes. The AI generates this automatically in app/_layout.tsx:
import { getAuth, signInAnonymously, onAuthStateChanged } from 'firebase/auth';

useEffect(() => {
  const auth = getAuth(app);
  return onAuthStateChanged(auth, (user) => {
    if (!user) signInAnonymously(auth).catch(console.error);
  });
}, []);

This is silent to end-users — no sign-up screen, no email/password.

Common errors → what to do

When deploy fails, Huxly shows a setup-required modal with the exact fix. Here's the reference if you want to know what each error means.

"Cloud Functions not provisioned"
The Firebase project hasn't been set up for Functions yet. Open the Firebase Console → Functions page → complete any setup prompts.
"Secret Manager API needs to be enabled"
The API for storing secrets isn't turned on for your project. Click the Enable link in the modal. Wait 30 seconds.
"Service account needs 'Service Account User' role"
The deployer can't act as the runtime. See Firebase Setup Step 4.
"Runtime service account cannot read secrets"
The runtime SA is missing Secret Manager Secret Accessor. See Firebase Setup Step 5.
"Secret missing from Secret Manager"
Your function declares defineSecret('OPENAI_API_KEY') but you haven't created OPENAI_API_KEY in Google Secret Manager. See Firebase Setup Step 7.
"Cannot create secrets — either grant permission or create manually"
Easy path: create the secret manually in Google Secret Manager. Power-user path: grant Secret Manager Admin to firebase-adminsdk so Huxly can create secrets going forward.
"A deploy of this function is still finalising on Google's side"
You clicked Deploy twice in quick succession. Google's first deploy is still finishing in the background. Wait 90 seconds, then click once more.
"Firebase project needs the Blaze plan"
Free tier of Firebase can't deploy Functions. Upgrade to Blaze (pay-as-you-go). You'll only be charged if you exceed the free tier, which most small apps don't.
CORS / 403 in browser console after deploy
The function's URL exists but the public invoker grant didn't land. Huxly auto-grants this on deploy — if you see this after a successful deploy, the auto-grant failed silently. Open the Functions page in Cloud Console, find your function, PERMISSIONS tab → ADD PRINCIPAL → allUsers + role Cloud Functions Invoker.

Updating a secret value

You don't need to redeploy the function to update a secret.

Supabase

Update the value in Huxly's Secrets tab → Save. Next function call picks up the new value.

Firebase

Update the value in Google Secret Manager:

  1. Open the secret
  2. Click + NEW VERSION
  3. Paste the new value
  4. Save

The function reads version: 'latest' so the next cold start picks up the new version. If your function has a warm instance running with the old value, redeploy to force a cold start.

Advanced mode

For users with existing complex Firebase setups (custom regions, custom service accounts, custom IAM policies, custom invoker configurations), Huxly's smooth-deploy enhancements can interfere.

In advanced mode, Huxly skips:

You get raw Cloud Functions API responses. Useful for diagnosing unusual setups or matching an existing deploy pipeline.

To enable: include advancedMode: true in the deploy request. UI toggle is planned for a future release.

Frequently asked

Can I call the function from outside my app (cURL, Postman)?

Supabase: yes, with the anon key as Authorization: Bearer <key>. Firebase: technically yes via raw POST, but the function's req.auth.uid check will reject calls without a valid Firebase auth token. Easier to test from your app.

How do I see logs?

Supabase: Edge Functions panel → click the function → Logs tab. Firebase: Cloud Console → Functions → click the function → Logs tab. Realtime, searchable, includes every invocation.

How much does it cost?

Supabase: free tier is 500K invocations/month. Beyond that, ~$2 per million.

Firebase: free tier is 2 million invocations/month, then $0.40 per million. Plus compute time (negligible for short functions).

Both providers have very generous free tiers — most apps stay free.

Can I have multiple functions?

Yes, unlimited. Each function is its own file. Huxly's panel lists them all and you can deploy them individually.

What if my function takes a long time (>30 seconds)?

Cloud Functions and Supabase Edge Functions both have configurable timeouts. For very long jobs (>1 minute), consider running them as a background task and returning a job ID the app can poll.

Still stuck?

Open a thread in Huxly Support, or check the per-error setup modals shown automatically when a deploy fails — each one has a direct link to the exact Google Cloud Console page that fixes the issue.