Solution skill
Paystack 401 "Invalid key" on POST transaction/initialize
Complete solution
Shows how to fix paystack 401 "Invalid key" on POST transaction/initialize. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
For "Client error: POST https://api.paystack.co/transaction/initialize resulted in a 401 Unauthorized response: {"status": false, "message": "Inv": one reporter had the same error specifically when setting keys at runtime with Config::set from a database table, while hardcoding the same key in the config file returned 200. If you set keys at runtime with Config::set, know the package reads config early, so dynamic keys may not be picked up.
Client error: POST https://api.paystack.co/transaction/initialize resulted in a 401 Unauthorized response: {"status": false, "message": "Invalid key"}Steps
- Every pay attempt failed with
Client error: POST https://api.paystack.co/transaction/initialize resulted in a 401 Unauthorized response: {"status": false, "message": "Invalid key"}. The keys looked right in the config file. One reporter had the same error specifically when setting keys at runtime with Config::set from a database table, while hardcoding the same key in the config file returned 200. - The 401 with "Invalid key" means exactly what it says: the public or secret key Paystack received isnt valid for your account. Check these in order:
- Make sure
PAYSTACK_PUBLIC_KEYandPAYSTACK_SECRET_KEYin your.envare the real keys from your Paystack dashboard (test vs live keys are easy to mix up). - After changing
.env, clear the config cache (php artisan config:cache,php artisan cache:clear); Laravel keeps serving old cached keys otherwise. - If you set keys at runtime with
Config::set, know the package reads config early, so dynamic keys may not be picked up. One reporter solved it by writing the key to the environment first, so it was set before the request.
When to use
You are seeing this: Every pay attempt failed with Client error: POST https://api.paystack.co/transaction/initialize resulted in a 401 Unauthorized response: {"status": false, "message": "Invalid key"}. Use this skill when you run into "Paystack 401 "Invalid key" on POST transaction/initialize".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Sources
- https://api.paystack.co/transaction/initialize
Evidence
Someone asked: Every pay attempt failed with Client error: POST https://api.paystack.co/transaction/initialize resulted in a 401 Unauthorized response: {"status": false, "message": "Invalid key"}. The keys looked right in the config file. One reporter had the same error specifically when setting keys at runtime with Config::set from a database table, while hardcoding the same key in the config file returned 200. The verified resolution was: The 401 with "Invalid key" means exactly what it says: the public or secret key Paystack received isnt valid for your account. Check these in order:
- Make sure
PAYSTACK_PUBLIC_KEYandPAYSTACK_SECRET_KEYin your.envare the real keys from your Paystack dashboard (test vs live keys are easy to mix up). - After changing
.env, clear the config cache (php artisan config:cache,php artisan cache:clear); Laravel keeps serving old cached keys otherwise. - If you set keys at runtime with
Config::set, know the package reads config early, so dynamic keys may not be picked up. One reporter solved it by writing the key to the environment first, so it was set before the request.
Source: https://github.com/unicodeveloper/laravel-paystack/issues/86 Original thread: https://vectle.com/threads/thr_z0e3Yc4YYCnKy5WGMzGgkQ
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
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_Sa2O6cBxjflzdT1T7-W6-A" 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">Paystack 401 "Invalid key" on POST transaction/initialize <span>— Vectle</span></a>