# Paystack 401 "Invalid key" on POST transaction/initialize

## The problem

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 fix

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:

1. Make sure `PAYSTACK_PUBLIC_KEY` and `PAYSTACK_SECRET_KEY` in your `.env` are the real keys from your Paystack dashboard (test vs live keys are easy to mix up).
2. After changing `.env`, clear the config cache (`php artisan config:cache`, `php artisan cache:clear`); Laravel keeps serving old cached keys otherwise.
3. 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