← All posts
·6 min read·GuardLayer

Supabase "No API key found in request": the fix

SupabaseAPI KeysNext.jsSecurity

"No API key found in request" is a 401 from Supabase's API gateway: the request reached https://<ref>.supabase.co without an apikey header, so it never got as far as Auth, PostgREST or Storage. Send your publishable (anon) key in the apikey header and the user's access token in Authorization. Don't follow the hint into putting a key in the URL, and never the secret key.

The full response, as pasted verbatim in looneyhills1-png/ninja-analytics#7 and refaitarek30-debug/Schichtplanung#19:

{"message":"No API key found in request","hint":"No `apikey` request header or url param was found."}

Older self-hosted stacks running Kong return the shorter {"message":"No API key found in request"}. Same meaning, same fix.

What does "No API key found in request" mean?

It means the gateway in front of your project looked for a key and found nothing. Every Supabase API path (/rest/v1, /auth/v1, /storage/v1, /realtime/v1) sits behind that gateway, and it rejects keyless requests before any service sees them. There's no Supabase docs page for the string, because no Supabase client ever triggers it: createClient throws supabaseKey is required at startup if the key is missing, and once it has one it attaches the header to every call.

So when you see this message, the request didn't come from a configured supabase-js client. It's the sibling of Supabase's "Invalid API key" error: that one means a key arrived but didn't match the project. This one means no key arrived at all.

The four requests that hit it

1. Hand-rolled fetch, curl or Postman calls. Someone calls /rest/v1/orders directly and forgets the header. Postman collections and n8n HTTP nodes are frequent offenders, because the key has to be added by hand.

2. Health checks and uptime monitors. The ninja-analytics issue is a check against /auth/v1/health that failed on every deploy. Its author nailed the cause: the gateway "rejects every request without an apikey header before it reaches the Auth service, even a health check that otherwise needs no auth of its own."

3. A link that opens a Supabase API URL in the browser. Browsers can't attach custom headers to a navigation. In Schichtplanung#19, users clicking the sign-up confirmation email landed on raw JSON with this message. The team's fix was to point their email templates at their own app instead, {{ .SiteURL }}/auth/callback?token_hash={{ .TokenHash }}&type=signup, and redeem the token_hash server-side with verifyOtp(). That's the same token-hash pattern Supabase documents for server-side auth, and it means the email link never asks the browser to talk to the gateway directly.

4. Proxies and middleware that strip headers. A reverse proxy or edge function that forwards requests to Supabase but rebuilds the header set without apikey produces this on every call. Log the outgoing headers at the proxy to confirm.

The fix that leaks your key

The hint says "request header or url param", and that second option is where things go wrong. Appending ?apikey=... makes the error disappear, so people put it in fetch URLs, image src attributes, cron jobs and webhook URLs. When the publishable key isn't enough, because RLS returns nothing, the next step is often the service role key, and then you get this:

"use client";

// "No API key found in request" went away once the key rode along in the URL.
export async function loadOrders() {
  const res = await fetch(
    `${process.env.NEXT_PUBLIC_SUPABASE_URL}/rest/v1/orders?select=*&apikey=${process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY}`
  );
  return res.json();
}
guardlayer scan · app/orders/load-orders.tsxLive engine output
Check failed
25/100 · F
  • Criticalapp/orders/load-orders.tsx:6

    Service role key exposed to the client

    Drop the NEXT_PUBLIC_ prefix so Next.js never puts the key in the browser bundle, and read it only in server code (a Route Handler or Server Action). Rotate the key immediately since it has been exposed.
  • Criticalapp/orders/load-orders.tsx:6

    Service role key used in client-side code

    Move all service-role usage into a server context (Route Handler, Server Action, or server-only module). On the client use only the anon key, protected by RLS.
  • Criticalapp/orders/load-orders.tsx:6

    Secret exposed through NEXT_PUBLIC_

    Drop the NEXT_PUBLIC_ prefix and read the value only on the server. Publishable/anon keys are fine to expose; secret keys, tokens, and passwords are not — rotate any that have shipped.

Two problems stack up here. The NEXT_PUBLIC_ prefix inlines the service role key into the JavaScript bundle, so anyone who opens DevTools has a key that bypasses RLS on every table. We've written up what an exposed service role key gives away. Putting it in the URL then copies it into places headers don't go: browser history, proxy and CDN access logs, error trackers that record request URLs, and analytics tools that capture page or resource URLs.

Even the publishable key doesn't belong in URLs you hand out. It's designed to be public, but a URL-embedded key can't be rotated without breaking every link that carries it.

How do I fix "No API key found in request"?

Send the key as a header. For the database or Auth API from a browser or a user-facing server route, that's two headers:

const res = await fetch(`${process.env.NEXT_PUBLIC_SUPABASE_URL}/rest/v1/orders?select=*`, {
  headers: {
    apikey: process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,   // identifies the project
    Authorization: `Bearer ${session.access_token}`,            // identifies the user, so RLS applies
  },
});

The apikey header gets you past the gateway. The Authorization header is what makes auth.uid() return the signed-in user. Without it, PostgREST runs the query as anon and RLS filters the rows accordingly. Better still, use supabase-js (createBrowserClient or createServerClient from @supabase/ssr), which sets both headers for you.

For a health check, the publishable key is enough:

curl -s -H "apikey: $SUPABASE_PUBLISHABLE_KEY" https://<ref>.supabase.co/auth/v1/health

For server-to-server jobs that genuinely need to bypass RLS (cron, a webhook receiver, an admin script), the secret key goes in the apikey header from server-only code, read from a variable without the NEXT_PUBLIC_ prefix. The new sb_secret_ keys are refused outright when they arrive from a browser, which is covered in Forbidden use of secret API key in browser. Which key goes where is laid out in publishable vs secret keys.

For email links, point the template at your own route and verify there, as in cause 3. A link should never need a key in it.

What GuardLayer catches

The sample above fires three critical findings: supabase/service-role-in-public-env and nextjs/public-env-secret for the NEXT_PUBLIC_ service role variable, and supabase/service-role-key-in-client for using it in a "use client" file. A literal sb_secret_... key pasted into a URL string in any file fires general/hardcoded-secret.

What it won't flag is a publishable key in a URL, because that's an operational smell rather than a vulnerability. It also can't see your uptime monitor's config or your dashboard email templates.

Quick self-check

# Keys riding in URLs
grep -rnE "[?&]apikey=" --include=*.ts --include=*.tsx --include=*.js --include=*.sql .

# Service role or secret keys in public env vars
grep -rnE "NEXT_PUBLIC_[A-Z_]*(SERVICE_ROLE|SECRET)" .

Then check your logging and error-tracking tools for any captured URL containing apikey=. If a secret or service role key shows up there, rotate it. Deleting the code doesn't un-log it.

FAQ

Does Supabase accept the API key as a URL parameter? The gateway's own hint says it looks for "request header or url param", so a query-string key can get past it. Use the header anyway: URLs end up in logs, history and analytics, and headers don't.

Why do I get "No API key found in request" when clicking a Supabase email link? Because the link opened a Supabase API URL in the browser, and a navigation can't send the apikey header. Point the template at your own route with {{ .TokenHash }} and call verifyOtp() server-side.

Which key should I send in the apikey header? The publishable (anon) key from browsers and user-facing routes, plus the user's access token in Authorization. The secret or service role key only from server-only code that needs to bypass RLS.

Is "No API key found in request" the same as "Invalid API key"? No. "No API key found" means nothing arrived. "Invalid API key" means a key arrived but doesn't belong to the project at that URL, usually a key from a different project or one that was rotated.

See which of your Supabase tables anyone can read, free

Connect your Supabase project read-only. GuardLayer checks RLS, policies, grants and functions as they are right now, and gives you the SQL to fix each problem. It never reads your rows and can't change anything.

Check my Supabase project

Prefer to check code instead? Scan your repo, no signup.

Keep reading