Skip to content

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. 1

    Confirm the error

    Open the bot log. Look for 401 unauthorized on the failed call.

  2. 2

    Open the Alpaca dashboard

    Sign in at Alpaca and open the API keys for the account.

  3. 3

    Generate a new key pair

    Create a fresh key and secret. Copy both values.

  4. 4

    Reconnect in Nyria

    Open the Integrations page and reconnect Alpaca with the new pair.

  5. 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

Try a paper bot first

No card required. Paper is free. Live trading from $15 a month.