Guide
Why does my Alpaca bot fail with 401 unauthorized?
A bot that fails with 401 unauthorized has an Alpaca key pair that no longer works. Alpaca keys don't expire on a schedule. Regenerating them in the Alpaca dashboard, or resetting the paper account, voids them. Generate a new pair and reconnect.
Official documentation
Fix an Alpaca 401 unauthorized
- 1
Confirm the error
Open the bot log. Look for 401 unauthorized on the failed call.
- 2
Open the Alpaca dashboard
Sign in at Alpaca and open the API keys for the account.
- 3
Generate a new key pair
Create a fresh key and secret. Copy both values.
- 4
Reconnect in Nyria
Open the Integrations page and reconnect Alpaca with the new pair.
- 5
Send a test alert
Send one alert and read the bot log entry.
What changed the key
- Regenerating keys in Alpaca voids the old pair.
- Resetting the paper account voids it too.
- Keys don't expire on a schedule.
- Nothing in Nyria changed the pair.
- Alpaca no longer recognises the old one.
Why a bot hits it later
- Alerts are what make a bot call Alpaca.
- The failure shows on the next alert.
- That can be well after the reset.
- The log entry carries the 401.
- Check the date on that log entry.
What reconnecting keeps
- Your bot settings are kept.
- Your history is kept.
- The webhook URL doesn't change.
- Alerts keep pointing at the same strategy.
- Only the key pair is replaced.
Not a 401
- A 422 means Alpaca paper refused the order.
- A 403 options_level_required is a different error.
- It means the options level is too low.
- Each one has its own fix.
- Read the exact code before you change keys.
Before a reset
- Note which bots use the account.
- Plan to reconnect right after the reset.
- Resetting is the usual cause of a 401.
- Nyria Paper needs no keys at all.
- Use it to check an alert while you reconnect.
Questions
- What does 401 unauthorized mean?
- Alpaca doesn't accept the key pair the bot used.
- Do Alpaca keys expire?
- No. They don't expire on a schedule.
- What voids a key pair?
- Regenerating keys or resetting the paper account.
- How do I fix it?
- Generate a new key pair and reconnect from Integrations.
- Do I lose my bot settings?
- No. Settings and history are kept.
- Does the webhook URL change?
- No. The URL belongs to the strategy.
Next
- Paste an alert into the alert tester to see how Nyria reads it.
- Step by step for one account: how to automate TradingView to Nyria Paper.
- Step by step for one account: how to automate Webhook to Nyria Paper.
- Alert tester.
Guides
Why is my trading bot not placing orders?
Open the bot's Logs tab. Seven states explain a bot that places nothing.
Read guideWhy does Nyria say Alpaca didn't accept these keys?
Alpaca refused the key ID and secret you pasted.
Read guideWhy does Alpaca say options_level_required?
Your Alpaca options level is below Level 3.
Read guideWhy does my Alpaca test order fail with 422?
Read error_detail in the bot log. It names the Alpaca paper rejection.
Read guideTry a paper bot first
No card required. Paper is free. Live trading from $15 a month.