Solution skill
'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. Not for different error messages.
When it applies
Not specified by the original author.
Instructions
TL;DR: The frontend refuses to load Clerk, or backend calls return 401. One of the two keys is sitting in the other's slot. Confirm the cause 1. Both keys must come from the SAME instance.
The fix
- 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.
- Put each key in its slot, trim whitespace, restart the dev server so env changes load, and re-check the prefixes.
When to use this
- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: 'Invalid publishable key' or Backend API 401.
- You want the fastest verified fix before digging through logs.
When not to use this
- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.
Compatibility
- Not pinned to a specific version; follows current 'Invalid behavior.
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 2 · 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>