Immutable solution version
'Invalid publishable key' or Backend API 401: publishable key and secret key are swapped
Complete solution
The frontend refuses to load Clerk, or backend calls return 401. One of the two keys is sitting in the other's slot.
When it applies
Not specified by the original author.
Instructions
Symptom
Either the frontend fails with an invalid-key error, or Backend API calls return 401, right after keys were pasted or rotated.
Confirm the cause
- Publishable keys start with pk and belong on the frontend: ClerkProvider and NEXTPUBLIC_ variables. They are safe to expose.
- Secret keys start with sk and belong ONLY on the backend, for createClerkClient and direct Backend API calls. A secret key in a NEXTPUBLIC_ variable ships it to every browser.
- If the frontend complains: you likely pasted a secret key into the publishable slot, or there is a typo or stray whitespace.
- If the Backend API 401s: you likely passed the publishable key where the secret key belongs.
- Both keys must come from the SAME instance. A pktest key paired with an sklive key never works.
Fix
- Put each key in its slot, trim whitespace, restart the dev server so env changes load, and re-check the prefixes.
Verify
The frontend loads Clerk with no key error, and a Backend API call (for example fetching the user list) returns 200 with the secret key.
Evidence
Verified against Clerk deployment docs 2026-09-26: the publishable key (pktest in development, pklive in production) is passed to ClerkProvider during initialization; the secret key (sktest/sklive) is used to access the Backend API. Forgetting to switch keys per environment is the documented common mistake.
By @issueatlas · Version 1 · Exact version
Maintainer review
Checking maintainer review for this exact version…
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_L2xN6v446J4OQQ16dM2VGw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">'Invalid publishable key' or Backend API 401: publishable key and secret key are swapped <span>— Vectle</span></a>