Supabase Edge Functions in Production: Deploys, Secrets, Logs and CORS
On this page
Supabase Edge Functions in production: deploy from CI, set secrets, handle CORS and read logs, plus the limits to check before launch.
Supabase Edge Functions hold up in production when you deploy from CI, set secrets per project, match the JWT setting to the caller, handle CORS for browser calls and know where the logs live. Each step has its own failure mode, and the sections below cover them. This guide is for founders and engineers who have a function working on a laptop and want it to hold up after launch. It follows Supabase's Edge Functions documentation, read on 21 November 2026, starting with the deploy guide.
Key takeaways
- Deploy with
supabase functions deployfrom a CI job that holds a Supabase access token, so no laptop ships production code. - Local and production secrets live in different places. A new production secret reaches your function without a redeploy.
- Request and response bodies do not appear in the logs. Log the fields you need, and convert headers to a plain object first.
- A request that gets no response within 150 seconds returns a 504, so send a response before the timeout and move slow work into a background task or a queue.
How do you deploy Supabase Edge Functions?
You log in and link the project, then run one deploy command. The CLI deploys every function in the supabase/functions folder, or one function when you name it.
supabase login
supabase link --project-ref your-project-id
supabase functions deploy
supabase functions deploy hello-world
A deployed function answers at https://[YOUR_PROJECT_ID].supabase.co/functions/v1/hello-world. To call it with curl, send a publishable key in the apikey header. The documentation notes that publishable keys differ between development and production, so a key that works in your local setup fails against the hosted project.
How do you deploy from CI?
Store a Supabase access token as a CI secret and run the deploy command on every push to your main branch. The documentation's GitHub Actions example keeps SUPABASE_ACCESS_TOKEN in the repository secrets and runs the deploy with the --yes flag. Its GitLab and Bitbucket examples set SUPABASE_ACCESS_TOKEN and SUPABASE_PROJECT_ID as variables and run npx supabase functions deploy --debug --yes. A CI deploy gives you one place to see what shipped and one history to roll back from.
What changes between local and production?
| Setting | Local development | Production |
|---|---|---|
| Secrets | Read from supabase/functions/.env |
Set with the CLI or the Dashboard |
| Publishable key | The key from your local stack | The key from the project's API settings |
| Logs | Printed to your terminal | The function's Logs tab in the Dashboard |
How do secrets work in Edge Functions?
A function reads secrets as environment variables, as the secrets guide describes. Supabase injects some for you: SUPABASE_URL, SUPABASE_DB_URL, the publishable and secret key variables and SUPABASE_JWKS, with the legacy SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY kept for older projects. You add the rest yourself.
On your machine, the stack loads supabase/functions/.env when you run supabase start. Add that file to .gitignore, because a committed .env exposes every secret in it to anyone who can read the repository. For production, push a whole file or a single value:
supabase secrets set --env-file .env
supabase secrets set STRIPE_SECRET_KEY=sk_live_...
supabase secrets list
Your functions read a new secret at once, with no redeploy. Four rules shape how you manage them:
- Set each secret in both places, because local development and production load them differently.
- A secret name cannot start with
SUPABASE_, because Supabase reserves that prefix. - Creating or deleting a production secret needs the Owner or Administrator role, and developers can view secrets without changing them.
- A project holds up to 100 secrets of up to 48 KiB each. Bundle related values into one JSON secret if you reach the cap.
Our guide to secrets management for startups covers rotation and who should hold which key.
Should you turn off JWT verification?
Keep it on for any function that your signed-in users call, and turn it off for callers that cannot send a user JWT. The function authorization guide states that the default is verify_jwt = true, so the platform validates the JWT before your handler runs. Cron jobs, workers, pg_net and other Edge Functions call with a secret key on the apikey header instead of a user JWT, and an external provider such as Stripe or GitHub sends no Supabase credentials at all. You set the check per function in supabase/config.toml:
[functions.hello-world]
verify_jwt = false
Turning the check off to clear a 401 during development removes the platform's check, and the guide warns that your own code then becomes the only thing that verifies the caller. A signed webhook verifies the provider's signature inside the handler, which our guide to Stripe webhooks in production walks through.
How do you handle CORS for browser calls?
A browser sends a preflight OPTIONS request before it calls your function, and the function must answer it with the right headers. The CORS guide shows a manual pattern that imports corsHeaders and returns them on every response:
import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors'
export default {
fetch: async (req) => {
if (req.method === 'OPTIONS') {
return Response.json({ ok: true }, { headers: corsHeaders })
}
try {
const { name } = await req.json()
return Response.json({ message: `Hello ${name}!` }, { headers: corsHeaders })
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
return Response.json({ error: message }, { status: 400, headers: corsHeaders })
}
},
}
Add the headers to the error response too. A browser hides a function's error body when the headers are missing, and the console shows a CORS error that has nothing to do with the real fault. The documentation describes a withSupabase wrapper that handles CORS and preflight requests for you.
How do you read Edge Function logs?
Open the Edge Functions section of the Dashboard and select the function, then choose the Logs tab, as the debugging guide describes. One list shows each invocation with its status code and run time, along with console output and uncaught exceptions, plus boot and shutdown events. The level follows the status code, so a 4xx response shows as a warning and a 5xx response as an error.
Four details save debugging time:
- Uncaught exceptions are logged with the error message and stack trace.
- Request and response bodies are not logged or retained. Log the specific fields you need with
console.log, and leave out sensitive data. - Logging
req.headersthroughJSON.stringifyprints{}, because a Headers object does not store its data in enumerable properties. Convert it first withObject.fromEntries(req.headers). - A log message holds up to 10,000 characters, and a function can log up to 100 events in any 10-second period. A noisy loop can reach that cap.
On your machine, the same messages print to the terminal where you run the function.
Which limits matter in production?
These values apply to the hosted platform, according to Supabase's limits page. Our guide to Edge Functions versus database functions explains how they shape the choice between the two.
| Limit | Value |
|---|---|
| Memory | 256 MB |
| Wall-clock duration | 150 seconds on Free, 400 seconds on paid plans |
| CPU time | 2 seconds per worker, with async I/O excluded |
| Request idle timeout | 150 seconds, then the caller gets a 504 |
| Function size | 20 MB bundled with the CLI, 5 MB bundled on the server |
| Functions per project | 100 on Free, 1,000 on Pro, 2,000 on Team |
| Outgoing mail ports | 25 and 587 are blocked |
The blocked mail ports matter if you send email over SMTP from a function. Use an email provider's HTTP API instead.
How do background tasks work?
A function can respond to the caller and keep working. Mark the promise with EdgeRuntime.waitUntil(promise) and skip the await, and the instance keeps running until that promise settles. The documentation lists uploads to Storage and database updates as typical uses. The wall-clock limit applies to background work, so a job that needs minutes belongs in a queue.
What do Edge Function invocations cost?
The Supabase pricing page, read on 21 November 2026, lists 500,000 invocations on the Free plan. Pro and Team include 2 million, then charge $2 per 1 million. A function that a page calls on every load can reach those numbers faster than a team expects, so cache responses where the data allows. Our Supabase pricing guide puts invocations next to the rest of the bill.
What should you check before launch?
- Deploy from CI with a token stored as a secret, and remove production access tokens from personal laptops.
- List the production secrets with
supabase secrets listand compare the names with your local.env. - Confirm that every function with
verify_jwtoff verifies the caller another way, as a webhook handler does with a signature. - Call each browser-facing function from the deployed front end and watch for CORS errors on the error path.
- Trigger a failure on purpose and confirm in the Logs tab that the message tells you what broke.
- Check each function against the memory and CPU limits with a realistic payload.
Frequently asked questions
Do I need to redeploy after I change a secret?
No. The documentation says functions read a new secret at once. A code change needs a deploy.
Why does my function work on my machine and fail in production?
Check the secrets first, because local development reads supabase/functions/.env and production reads the secrets you set on the project. Read the Logs tab for the real error after that. The publishable key differs between environments, so confirm that your client uses the production one.
Why do I see a CORS error when my function throws?
The error response lacks the CORS headers, so the browser blocks it and reports a CORS failure. Return corsHeaders on every response, errors included.
Why does my function return a 504?
The function did not send a response within the 150-second idle timeout. Send a response before the timeout and move the slow work into a background task or a queue.
Can an Edge Function send email over SMTP?
Not on ports 25 or 587, which Supabase blocks for outgoing connections. Send through a provider's HTTP API.
Summary
A production Edge Function needs a CI deploy, secrets set on the project, a deliberate JWT setting, CORS on every response and logs you know how to read. Check the limits against real traffic before launch. If you want an engineer to review your functions and the setup around them, our backend and API development service covers PostgreSQL design, authentication, APIs and cloud infrastructure for startups.
Topic: AI-built apps & Supabase